From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Use the React router hooks: useNavigate

Use the React router hooks: useNavigate

- [Instructor] React Router offers a few useful hooks that you can use in your React applications to perform navigation tasks. First, you have useParams, that returns an object of key/value pairs of the dynamic params from the current URL that matches the route path. Then you have useNavigate, that returns a function that lets you navigate programmatically to another view. Finally, you have useLocation, that returns the current location object. And this can be very useful if you'd like to perform some side effects whenever the current location changes. For the next example, we're going to use useNavigate and useLocation. Basically what we want is to allow the user to navigate to another view to display one image individually. So let's go back to the source code. So, first, we're going to go to Card. And I'm going to add to this code this useNavigate. That's going to be from react-router-dom also. So we're going to…

Contents