What I'm trying to do here is to simplify the code using hooks
Here is the action file
export const getThings = (num) => async dispatch => {
dispatch({ type: constants.GET_HOME_PAGE_REQ });
const [res, error] = useFetch('get', api + "/latest/" + num, {});
useEffect(() => {
res && dispatch({
type: constants.GET_HOME_PAGE_RES,
status: res.status,
payload: res.data.message,
});
}, [res, dispatch]);
useEffect(() => {
error && dispatch({
type: constants.GET_HOME_PAGE_ERROR,
message: error.message,
status: error.status,
});
} , [error, dispatch]);
};
and the error I'm getting
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app See for tips about how to debug and fix this problem.
const [res, error] = useFetch('get', api + "/latest/" + num, {});this is an invalid call. Hook can be called inside of the body of a function component. So don't call in your async functiongetThings.