Hi all,
New to DHIS2 development and new to React (all my previous experience is in Vue js).
I am attempting to fetch sharing information for my apps Datastore key which involves querying the sharing api endpoint with the datastore key id.
If I hard code the query with the datastore key id all works well. But I am not really sure how chain up the queries so that I can first query the datastore key metadata for the key and then provide this to the second query to get the sharing data.
I am new to React and so I am tying myself in knots following tutorials about useState and useEffect. Any guidance would be greatly appreciated.
Query to fetch datastore key metadata:
const dataStoreKeyMetaData = {
results: {
resource: `dataStore/app-namespace/settings/metaData`,
paging: false
}
}
Query to fetch datastore key sharing data:
const dataStoreKeySharingData = {
results: {
resource: 'sharing',
params: ({id}) => ({
id,
type: "dataStore"
})
}
}
Current functional component that simply returns the sharing data. I have hard coded the id in for now.
const AccessInfo = () => {
const {loading,error,data} = useDataQuery(dataStoreKeySharingData,{variables:{id:"qOIScqfJ7Ln"}})
return (
<div>
{loading}
{error && <div>Error: {error.message}</div>}
{data && <pre>{JSON.stringify(data,null,2)}</pre>}
</div>
)
}
Edit:
Actually I have sort of solved the issue by converting the parent object component into a functional one and then passing the id as a prop to the AccessInfo component
Solution: Learn more about React