I am dealing with react query problem, I have separate file with all the queries:
const useFetchApTableQuery = (date: string): UseQueryResult => {
const axiosClient = axios.create()
const fetchApTableQuery = async (): Promise<AxiosResponse> => {
const res = await axiosClient.get(`${API_ROUTES.apTable}?date=${date}`)
return res.data.data.map((record: any) => APParser(record))
}
return useQuery([date], fetchApTableQuery, {
})
}
and then iam calling my query in component like this
const APTablePage = (): JSX.Element => {
const [selectedPeriod, setSelectedPeriod] = useState<string>('')
const { data: tableData } = useFetchApTableQuery(selectedPeriod)
....
}
The problem is need useQuery to omit fetching data when selectedPeriod param is empty (selected period is also being fetched from api when component mounts so I don't have any default value to set for selected period). is there any possibility to make useQuery pass for example null to {data:tabledata} variable when selectedPeriod is empty string ?
Thank you :-)
I have tried dealing with this via useEffect but unfortunately I cannot call hooks in useffect