Skip to content

Instantly share code, notes, and snippets.

@jasonleehodges
Created March 21, 2020 22:35
Show Gist options
  • Save jasonleehodges/e1dd08fe53667d2276a5b0d310a7b26f to your computer and use it in GitHub Desktop.
Save jasonleehodges/e1dd08fe53667d2276a5b0d310a7b26f to your computer and use it in GitHub Desktop.
Example of dispatching actions without Thunks using custom hooks
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