React (intermediate) Flashcards

1
Q

install React Router with the command:

A

npm install react-router-dom

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

The use_____ hook is a feature of React Router that allows you to access URL parameters in your component. It’s particularly useful when you’re working with d____ routes.

A

The useParams hook is a feature of React Router that allows you to access URL parameters in your component. It’s particularly useful when you’re working with dynamic routes

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

We define the route rendering a specific note “ex_____ style” by marking the parameter with a colon - :id

A

We define the route rendering a specific note “express style” by marking the parameter with a colon - :id

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

this hook allows you to pass state to the next route, which can be useful for sharing data between routes without using global state management.

A

useNavigate

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

the e________ prop is used to specify the React component that should be rendered when the route’s path matches the current URL.

A

the element prop is used to specify the React component that should be rendered when the route’s path matches the current URL.

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

The element prop takes a ___ expression, not just a component reference.

A

The element prop takes a JSX expression, not just a component reference.

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

Hooks are like functional m____s that let you create and compose your own abstractions.

A

Hooks are like functional mixins that let you create and compose your own abstractions.

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

If you only allow one useState() call per component, you lose the ability of custom Hooks to introduce local s___. Which is the point of custom Hooks.

A

If you only allow one useState() call per component, you lose the ability of custom Hooks to introduce local state. Which is the point of custom Hooks.

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

it’s likely that adopting H___s could reduce your b____ size because code using Hooks tends to m____ better than equivalent code using classes.

A

it’s likely that adopting Hooks could reduce your bundle size because code using Hooks tends to minify better than equivalent code using classes.

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

Hooks are fully encapsulated — each time you call a Hook, it gets isolated l___ s___ within the currently executing component.

A

Hooks are fully encapsulated — each time you call a Hook, it gets isolated local state within the currently executing component.
(They’re not a way to share state — but a way to share stateful logic. We don’t want to break the top-down data flow!)

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

___ serves the same purpose as componentDidMount, componentDidUpdate, and componentWillUnmount in React classes, but unified into a single API.

A

useEffect serves the same purpose as componentDidMount, componentDidUpdate, and componentWillUnmount in React classes, but unified into a single API.

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

Hooks don’t work inside c____s. But you can use them instead of writing c____s.

A

Hooks don’t work inside classes. But you can use them instead of writing classes.

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

Hooks offer a powerful and expressive new way to reuse f_____ between c______s

A

Hooks offer a powerful and expressive new way to reuse functionality between components

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

In React, when you include a prop name without assigning it a value, it’s implicitly set to t___. This is a convenient shorthand for boolean props.

A

In React, when you include a prop name without assigning it a value, it’s implicitly set to true. This is a convenient shorthand for boolean props.

<Navigate replace to="/login" />

is
~~~
<Navigate replace={true} to=”/login” />
~~~

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

In the context of React and server-side rendering (SSR), “h______” refers to the process of attaching event listeners and state to the static HTML that was rendered on the server, essentially making it interactive on the client side

A

In the context of React and server-side rendering (SSR), “hydration” refers to the process of attaching event listeners and state to the static HTML that was rendered on the server, essentially making it interactive on the client side

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

If you have cleanup code without corresponding s_____ code, it’s usually a code smell

A

If you have cleanup code without corresponding setup code, it’s usually a code smell

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

By default, Effects run after ___ render

A

By default, Effects run after every render

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

Setting state t______s rendering

A

Setting state triggers rendering

19
Q

Effects only run on the c____. They don’t run during s____ rendering.

A

Effects only run on the client. They don’t run during server rendering.

20
Q

Avoid relying on o____s and f_____s as dependencies

A

Avoid relying on objects and functions as dependencies

21
Q

When you want a component to “remember” some information, but you don’t want that information to trigger new renders, you can use a r___

A

When you want a component to “remember” some information, but you don’t want that information to trigger new renders, you can use a ref

22
Q

A ref is like a secret pocket of your component that React doesn’t track. For example, you can use refs to store t____ IDs, D___ elements, and other objects that don’t impact the component’s rendering output.

A

A ref is like a secret pocket of your component that React doesn’t track. For example, you can use refs to store timeout IDs, DOM elements, and other objects that don’t impact the component’s rendering output.

23
Q

There are two common cases in which you don’t need Effects:

You don’t need Effects to t_____ data for rendering.
You don’t need Effects to handle user e_____s.

A

There are two common cases in which you don’t need Effects:

You don’t need Effects to transform data for rendering.
You don’t need Effects to handle user events.

24
Q

useRef returns an object with a single property: c_______

A

useRef returns an object with a single property: current

25
Q

On the next renders, useRef will return the s____ object.

A

On the next renders, useRef will return the same object.

26
Q

When you change the r__.current property, React does not re-render your component. React is not aware of when you change it because a ref is a plain JavaScript object.

A

When you change the ref.current property, React does not re-render your component. React is not aware of when you change it because a ref is a plain JavaScript object.

27
Q

Changing a r__ does not trigger a re-render.

A

Changing a ref does not trigger a re-render.

28
Q

By using a ref, you ensure that:

  1. You can store inf_____ between re-renders
  2. Changing it does not trigger a re-r_____
  3. The information is l____ to each copy of your component
A

By using a ref, you ensure that:

  1. You can store information between re-renders (unlike regular variables, which reset on every render).
  2. Changing it does not trigger a re-render (unlike state variables, which trigger a re-render).
  3. The information is local to each copy of your component (unlike the variables outside, which are shared).
29
Q

Do not write or read ref.c____ during rendering.

A

Do not write or read ref.current during rendering.

Reading or writing a ref during rendering breaks React’s expectations that the body of your component behaves like a pure function:

  1. If the inputs (props, state, and context) are the same, it should return exactly the same JSX.
  2. Calling it in a different order or with different arguments should not affect the results of other calls.
30
Q

You can read or write refs from event h____s or effects instead.

A

You can read or write refs from event handlers or effects instead.

31
Q

It’s particularly common to use a ref to manipulate the D___.

A

It’s particularly common to use a ref to manipulate the DOM.

32
Q

useReducer is very similar to useState, but it lets you move the state update logic from event handlers into a single function outside of your c_____.

A

useReducer is very similar to useState, but it lets you move the state update logic from event handlers into a single function outside of your component.

33
Q

Reducers must be p___. Similar to state updater functions, reducers run during rendering!

A

Reducers must be pure. Similar to state updater functions, reducers run during rendering!
(same inputs always result in the same output)

34
Q

Initially, myRef.current will be n___

A

Initially, myRef.current will be null

35
Q

If you pass a function to useState, React will only call it during in______.

A

If you pass a function to useState, React will only call it during initialization.

36
Q

If you’re worried about recomputing too often, the useM___ Hook can help.

A

If you’re worried about recomputing too often, the useMemo Hook can help.

37
Q

It is not possible to use the useMatch hook in the component which defines the r___ed part of the application

A

It is not possible to use the useMatch hook in the component which defines the routed part of the application

38
Q

BrowserRouter is a Router that uses the HTML5 h_____ API (pushState, replaceState and the popState event) to keep your UI in sync with the URL.

A

BrowserRouter is a Router that uses the HTML5 history API (pushState, replaceState and the popState event) to keep your UI in sync with the URL.

39
Q

BrowserRouter is a Router that uses the HTML5 history API (pushState, replaceState and the popState event) to keep your U_ in sync with the U__.

A

BrowserRouter is a Router that uses the HTML5 history API (pushState, replaceState and the popState event) to keep your UI in sync with the URL.

40
Q

useMemo won’t make the f___ render faster. It only helps you skip unnecessary work on updates.

A

useMemo won’t make the first render faster. It only helps you skip unnecessary work on updates.

41
Q

JSX elements must have one p____ element

A

JSX elements must have one parent element

42
Q
function HomeButton() {
  const navigate = useNavigate();

  return (
    <button onClick={() => n\_\_\_\_('/')}>Go to Table of Contents</button>
  );
}
A
function HomeButton() {
  const navigate = useNavigate();

  return (
    <button onClick={() => navigate('/')}>Go to Table of Contents</button>
  );
}
43
Q

The _____ hook returns a location object containing information about the current URL.

A

The useLocation() hook returns a location object containing information about the current URL.