I am using Redux store and connector components am using mapStateToProps and mapDispatchToProps to store data, now using Hooks I want to trigger fetch call on first page load but don’t want to use useEffect as it is not recommended these days
after lot of research got to know about useQuery, swr, redux-query but still couldn’t understand this clearly. Will using useQuery, react-query eliminates redux store, I want redux store to be maintained.
const { data, isFetching, isLoading } = useQuery(
['fetchEmployee', id],
() => getEmployee(id),
{
initialData: initial,
onSettled: () => dispatch(clearWaiting()),
onError: (err) => dispatch(showError(err)),
}
);
This is the useQuery Hook example. Seems like this doesn’t use redux store. Please Can someone suggest me a solution
2
Answers
U Should try axios simply make a. function in ur src/api folder and call it in your component above return this is not a good practice but will work as a beginer
I didn’t understand your question.
If you want to use react query instead of using useEffect you can use useQuery and it will give you data, loading states, and other useful things to reduce using useState also.
If your question if can you replace redux with react query? you can because react query has its own cache and global state.
can you explain more?