Reputation: 241
which way is correct ?
way 1:
const dispatch = useDispatch();
const add = useCallback(() => {
}, [dispatch]);
way2:
const dispatch = useCallback(() => {
return useDispatch();
}, []);
const add = useCallback(() => {
}, [dispatch]);
................................................................................................................................................................................
Upvotes: 0
Views: 101
Reputation: 456
The first way for sure: hooks can only be called in the context of a functional component, and not in the body of another hook call (hence you cannot nest useDispatch inside useCallback)
Upvotes: 1