My props of my export function : projectId and identityPseudonymGroup are accessible in the use effect with the log console, i.e. I have results but not in the fetch body. However they are global variables. Even with the use state, it doesn't work. The error is "Uncaught (in promise) TypeError : Failed to fetch"
const Export = ({identityPseudonymGroup, projectId}) => {
useEffect(() => {
console.log("id group" + identityPseudonymGroup)
console.log("id project" + projectId)
fetch("http://localhost:4000/api/observations/pacs/aggregation", {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${keycloak.token}`,
},
body: JSON.stringify({
'project_id': `${projectId}`,
'identity_pseudonym_group': `${identityPseudonymGroup}`
})
})
.then(response => response.json())
.then(response => {
var data = response;
setData(response)
Object.keys(response).map((key, index) => setChoiceStudy(array => [... array, key])) // select all studies for the filter
// Select all modalities and series
Object.keys(response)
.map((key, index) => (
response[key].map((value) => {
setChoiceModality(array => [... array, value['modality']])
setChoiceSeriesName(array => [... array, value['series']])
})));
})
}, []);