Skip to content

Instantly share code, notes, and snippets.

@itaditya
Last active October 5, 2020 14:23
Show Gist options
  • Save itaditya/3ac5c315f7a8205fb92fcb909433413d to your computer and use it in GitHub Desktop.
Save itaditya/3ac5c315f7a8205fb92fcb909433413d to your computer and use it in GitHub Desktop.
(Blog) Build a Redux hooked app
function useLoadFoodData() {
const [stateAPIStatus, setAPIStatus] = useState('idle');
const dispatch = useDispatch();
useEffect(() => {
setAPIStatus('loading');
loadFoodData()
.then((data) => {
dispatch({
type: ACTIONS.LOAD_MENU,
payload: {
menu: data,
},
});
setAPIStatus('success');
})
.catch((error) => {
setAPIStatus('error');
});
}, [dispatch]);
return stateAPIStatus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment