Created
August 21, 2019 08:03
-
-
Save op1ekun/c071292d6ba8c9610de09240963d184b to your computer and use it in GitHub Desktop.
usePush hook provides functions for dispatching push action directly or creating a callback.
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
import { push } from 'connected-react-router'; | |
import { useCallback } from 'react'; | |
import { useDispatch } from 'react-redux'; | |
export default () => { | |
const dispatch = useDispatch(); | |
const action = useCallback((path: string) => dispatch(push(path)), [dispatch]); | |
const handleAction = useCallback((path: string) => () => action(path), [action]); | |
return { | |
push: action, | |
handlePush: handleAction, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment