Last active
October 5, 2020 14:23
-
-
Save itaditya/3ac5c315f7a8205fb92fcb909433413d to your computer and use it in GitHub Desktop.
(Blog) Build a Redux hooked app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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