Fetching dataquery

Hi All,
I tried to run data query resource:analytics.
But the result console undefined
my code below:

const myanalytic = {
results: {
resource: ‘analytics’,
params: {
dimension: [‘dx:y1gIMkQteQr’,‘pe:LAST_12_MONTHS’],
const { loading, error, data } = useDataQuery(myanalytic);

thank you

Hello @Channara

Here is something that might help.

If the data of the useDataQuery hook is undefined, it either means it is still loading (loading == true) or there is an error with the query. The latter is most likely. You could try logging the error or loading to see if the query had issues or is still loading.

This is from the DHIS2 App Runtime Documentation


Hi @nnkogift
I follow instruction step link, Yes it works fine for programs or indicators. But when i use resource:analytics. it show undefined.


What does console.log(error) print?

no error display.
but i use many useDataQuery hook in one function, can be that problem?


Do you mean you use the useDataQuery hook like this?

const Component = () =>{
     const { data: data1, error: error1, loading: loading1} = useDataQuery(query1)
      const { data:data2, error: error2, loading:loading2} = useDataQuery(query2)


This may work (assuming the variables for error, loading, and, data are not mixed up). There is a simpler way, however, of combining such queries. You could use only one useDataQuery hook with the two queries passed in one object, they just need to have different keys. An example;

const queries = {
    indicators: {
        resource: 'indicators',
        params: {
            fields: ['id', 'displayName']
    analytics: {
        resource: 'analytics',
        params: {
            dimension: ['dx:y1gIMkQteQr', 'pe:LAST_12_MONTHS'],
            filter: [

const Component = () =>{
    const {error, loading, data} = useDataQuery(queries)
    //data will contain an object of all your queries' results

Perhaps you could try implementing the queries this way and see if the problem is still there.


Yes, i use many useDataQuery, it doesn’t show any error, but the result is undefined.
when i combine in one useDataQuery, yes sure, it works fine.

many thank for supporting.


Welcome :pray:t5: