Skip to content

Instantly share code, notes, and snippets.

@op1ekun
Created August 21, 2019 08:03
Show Gist options
  • Save op1ekun/c071292d6ba8c9610de09240963d184b to your computer and use it in GitHub Desktop.
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.
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