Mid From PDF React React.js

How do you programmatically navigate in React Router?

Short answer: You can navigate programmatically using the useHistory hook (React Router v5) or useNavigate hook (React Router v6). For React Router v5 (useHistory): import { useHistory } from 'react-router-dom'; function MyComponent() { const history = useHistory(); const goToHome = () => { history.push('/'); }; return <button onClick={goToHome}>Go to Home</button>;

Example code

}
For React Router v6 (useNavigate): import { useNavigate } from 'react-router-dom'; function MyComponent() { const navigate = useNavigate(); const goToHome = () => { navigate('/'); }; return <button onClick={goToHome}>Go to Home</button>;
} React Performance Optimization

Real-world example (ShopNest)

ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details