import { useDispatch } from ‘react-redux’;
const dispatch = useDispatch();
const fetchUser = async (dispatch) => {
const user = await fetch('https://api.example.com/user/1');
dispatch({ type: 'FETCH_USER', payload: user });
};
Fetch User
why thunk should be used
in here onClick of a button onClick={fetchUser} this is being done?.in here the dispatch will occur
then whats the use of thunk
in when should i write thunks