i use react-query to fetch some data ,and i need to call fetchPagesContent function in useQuery after fetchlangs function is done, because i need dynamic ID of lang to use it in fetchPagesContent function how i can dow that with react-query
import React, { createContext,useState,useEffect } from 'react'
import { useQuery } from 'react-query'
const fetchPagesContent = async () => {
const resp = await fetch('http://127.0.0.1:8000/api/content-pages/lang_id=1');
return resp.json();
}
const fetchlangs = async () => {
const resp = await fetch('http://127.0.0.1:8000/api/languages');
return resp.json();
}
export const AppContext = createContext();
export default function AppContextProvider({children}) {
const resp = useQuery('langs',fetchlangs );
const resp = useQuery('page',fetchPagesContent);
return (
<AppContext.Provider value={resp}>
{children}
</AppContext.Provider>
)
}
useQuerywith the same key (best abstracted in a custom hook) wherever you need your data