UNPKG

react-router-on-navigate

Version:

A simple component which returns a callback via the `onNavigate` prop when the user navigates using React Router

21 lines (15 loc) 369 B
import { useEffect } from 'react' import { useLocation } from 'react-router-dom' const displayName = 'OnNavigate' const Component = props => { const { onNavigate } = props const { pathname } = useLocation() useEffect(() => { onNavigate && onNavigate() }, [pathname, onNavigate]) return null } Component.displayName = displayName export default Component