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: useLocation
From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Use the React router hooks: useLocation
- [Instructor] So now we want to discover another hook, which is useLocation. And this hook allows to get the information of the current location. So we're going to use that to actually get, like, the state. So this is going to return a state object and we also need to add to the scope another state. Remember that this is from our global state, not from, but useFirestoreContext and this is going to be the state. So in order to avoid any conflict, I'm just going to rename this one to routerState, like this. We're going to need also, again, to use this useNavigate, that returns a function. And we're going to use that to allow the user to go back to where, like, here, we've got this function, we're going to add this navigate and this will allow the user to go back. Because you see that here, you can read Back. So now, what we want is to actually use this information to get whatever data is sent along during the navigation…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Install React router DOM v62m 53s
-
(Locked)
Configure the routes and create a navigation component2m 51s
-
(Locked)
Use Link component to navigate between pages4m 58s
-
(Locked)
Allow navigation between multiple views5m 39s
-
(Locked)
Conditional rendering and protected route4m 45s
-
(Locked)
Use the React router hooks: useNavigate4m 58s
-
(Locked)
Use the React router hooks: useLocation4m 35s
-
(Locked)
Create the routes for "NotFound" and "Profile"5m 15s
-
(Locked)
Display the active link3m 42s
-
(Locked)
-
-
-