useNavigateWrapper

A custom React hook that wraps react-router-dom's useNavigate for typed navigation. Must be used within a react-router-dom context.

Installation

import { useNavigateWrapper } from 'uxp/components';

Signature

function useNavigateWrapper(): CustomNavigateFunction

Examples

const MyComponent = () => {
  const navigate = useNavigateWrapper();
  return <button onClick={() => navigate('/home')}>Go to Home</button>;
};
const MyComponent = () => {
  const navigate = useNavigateWrapper();
  return (
    <div>
      <button onClick={() => navigate('/profile', { state: { userId: 123 } })}>
        Go to Profile
      </button>
      <button onClick={() => navigate(-1)}>Go Back</button>
    </div>
  );
};

Last updated