React Router Flashcards

1
Q

What does React Router enable?

A

React Router enables client-side routing for single-page applications (SPAs).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a “dynamic segment” in React Router?

A

A dynamic segment in React Router is a part of the URL path that starts with : and captures a variable value. For example, in <Route></Route>, :projectId and :taskId are dynamic segments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you provide data to a route element before it renders in React Router?

A

You can define a “loader” function for each route to provide data, and that data is made available to your components through useLoaderData.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are route actions in React Router, and when are they called?

A

Route actions are functions used to perform data mutations when an app sends non-GET submissions (e.g., “post,” “put,” “patch,” “delete”) to a route. They are called when these submissions occur.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you access dynamic parameters from the current URL in React Router?

A

You can use the useParams hook to obtain an object containing key-value pairs of the dynamic parameters from the current URL that match the route’s path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a <NavLink> in React Router, and what makes it special?</NavLink>

A

A <NavLink> in React Router is a specialized version of <Link. It's aware of whether it is "active" or "pending," making it useful for building navigation menus like breadcrumbs or tabs to highlight the currently selected item.</NavLink>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When should you use redirect in React Router, and when should you use useNavigate?

A

You should use redirect in route loaders and actions when a redirect is in response to data. useNavigate is typically used within components to trigger programmatic navigation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the useNavigate hook return in React Router?

A

The useNavigate hook returns a function that allows you to navigate programmatically within your React Router application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is “Suspense” in the context of React Router?

A

Suspense in React Router is a feature that allows you to declaratively specify loading states and fallback UI while data is being loaded for a route.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you specify where the child routes should be rendered in the root route in React Router?

A

You specify where child routes should be rendered in the root route by using the <Outlet> component.</Outlet>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does React Router handle form data compared to traditional server requests?

A

React Router serializes form data and uses client-side routing to send it to a route action, rather than sending it to the server as a traditional request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens when a POST action of a route is called in React Router?

A

When a POST action of a route is called, React Router recognizes that data has changed, and all useLoaderData hooks will automatically update.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can loaders and actions in React Router return a Response?

A

Yes, both loaders and actions in React Router can return a Response, which allows for handling server responses and data retrieval.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of “revalidation” in React Router?

A

The purpose of “revalidation” in React Router is to update the data on a page after an action redirects. This process calls all the loaders for the data to obtain the latest values, and useLoaderData returns new values, causing components to update.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you navigate back one step in the route navigation in React Router?

A

To go back one step in the route navigation in React Router, you can use the useNavigate(-1) function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly