Created
March 21, 2020 22:35
-
-
Save jasonleehodges/e1dd08fe53667d2276a5b0d310a7b26f to your computer and use it in GitHub Desktop.
Example of dispatching actions without Thunks using custom hooks
This file contains hidden or 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
import { useDispatch } from 'react-redux'; | |
import { setData } from '../actions'; | |
export const useDataService = () => { | |
const dispatch = useDispatch(); | |
const getData = () => { | |
fetch(url) | |
.then(resp => resp.json()) | |
.then(data => dispatch(setData(data)); | |
}; | |
return { | |
getData, | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment