useEffect( ) / Callback() / Reducer() / Context() Flashcards

(33 cards)

1
Q

The dependencies argument of useEffect(callback, dependencies) lets you control when the s____-e_____ runs.

A

The dependencies argument of useEffect(callback, dependencies) lets you control when the side-effect runs.

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

If the dependencies are not provided, the side-effect runs after _____ rendering.

A

If the dependencies are not provided, the side-effect runs after every rendering.

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

If the dependencies are an empty array [] the side-effect runs _____ after the ______ rendering.

A

If the dependencies are an empty array []: the side-effect runs once after the initial rendering.

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

If the dependencies has props or state values [prop1, prop2, …, state1, state2]: the side-effect runs ____ after____ rendering and then only when any d______ value changes.

A

If the dependencies has props or state values [prop1, prop2, …, state1, state2]: the side-effect runs once after initial rendering and then only when any dependency value changes.

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

The dependencies argument of the useEffect() lets you catch certain component lifecycle events: when the component has been m______-ed or a specific prop or state value has changed.

A

The dependencies argument of the useEffect() lets you catch certain component lifecycle events: when the component has been mounted or a specific prop or state value has changed.

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

M_____ing specifically refers to the process of inserting a component into the DOM for the first time.

A

Mounting specifically refers to the process of inserting a component into the DOM for the first time.

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

useEffect(callback, [prop, state]) invokes the callback once after mounting, and again after committing the changes to the ___, if and only if any value in the dependencies array [prop, state] has changed.

A

useEffect(callback, [prop, state]) invokes the callback once after mounting, and again after committing the changes to the DOM, if and only if any value in the dependencies array [prop, state] has changed.

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

By using the d________s argument of useEffect(), you control when the side-effect is called, independently from the rendering cycles of the component. Again, that’s the essence of useEffect() hook.

A

By using the dependencies argument of useEffect(), you control when the side-effect is called, independently from the rendering cycles of the component. Again, that’s the essence of useEffect() hook.

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

By using the dependencies argument of useEffect(), you control _____ the side-effect is called, independently from the rendering cycles of the component. Again, that’s the essence of useEffect() hook.

A

By using the dependencies argument of useEffect(), you control when the side-effect is called, independently from the rendering cycles of the component. Again, that’s the essence of useEffect() hook.

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

If the callback of useEffect(callback, deps) returns a f______, then useEffect() considers that function as an effect cleanup

A

If the callback of useEffect(callback, deps) returns a function, then useEffect() considers that function as an effect cleanup

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

If the callback of useEffect(callback, deps) returns a function, then useEffect() considers that function as an effect c_____

useEffect(function callback() => {
  // Side-effect...

  return function cleanup() { <<<<<<<<
    // Side-effect cleanup...  <<<<<<<<
  };
}, dependencies);
A

If the callback of useEffect(callback, deps) returns a function, then useEffect() considers that function as an effect cleanup

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

Cleanup works the following way:

A) After i_____ rendering, useEffect() invokes the callback with the side-effect. cleanup function is ___ invoked.

B) On later renderings, before invoking the next side-effect callback, useEffect() i_____s the cleanup function from the previous side-effect execution (to clean up everything after the previous side-effect), then i______s the current side-effect.

C) Finally, after unm_____ing the component, useEffect() invokes the cleanup function from the latest side-effect.

A

Cleanup works the following way:

A) After initial rendering, useEffect() invokes the callback with the side-effect. cleanup function is not invoked.

B) On later renderings, before invoking the next side-effect callback, useEffect() invokes the cleanup function from the previous side-effect execution (to clean up everything after the previous side-effect), then invokes the current side-effect.

C) Finally, after unmounting the component, useEffect() invokes the cleanup function from the latest side-effect.

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

useCallback(callbackFun, deps) is helpful when given the same dependency values as deps, the hook returns the same function instance between renderings (aka m______tion):

A

useCallback(callbackFun, deps) is helpful when given the same dependency values as deps, the hook returns the same function instance between renderings (aka memoization)

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

Context.Provider component available on the context instance is used to provide the context to its ____ components, no matter how deep they are.

A

Context.Provider component available on the context instance is used to provide the context to its child components, no matter how deep they are.

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

Context.P____ component available on the context instance is used to provide the context to its child components, no matter how deep they are.

A

Context.Provider component available on the context instance is used to provide the context to its child components, no matter how deep they are.

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

a way to use useContext() is with a render f____ supplied as a c____ to Context.Consumer special component available on the context instance

A

a way use useContext() is with a render function supplied as a child to Context.Consumer special component available on the context instance

import { Context } from './context';

function MyComponent() {
  return (
    <Context.Consumer>
      {value => <span>{value}</span>}
    </Context.Consumer>
  );
}
17
Q

a way to use useContext() is with a render function supplied as a child to Context.C____ special component available on the context instance

A

a way use useContext() is with a render function supplied as a child to Context.Consumer special component available on the context instance

import { Context } from './context';

function MyComponent() {
  return (
    <Context.Consumer>
      {value => <span>{value}</span>}
    </Context.Consumer>
  );
}
18
Q

You can have how many consumers for a single context?

A

You can have as many consumers as you want for a single context.

19
Q

If the context value changes (by changing the value prop of the provider <Context.P____ value={value} />), then all consumers are immediately notified and re-rendered.

A

If the context value changes (by changing the value prop of the provider <Context.Provider value={value} />), then all consumers are immediately notified and re-rendered.

20
Q

If the context value changes (by changing the value prop of the provider <Context.Provider value={value} />), then all consumers are immediately notified and re-r_____-ed.

A

If the context value changes (by changing the value prop of the provider <Context.Provider value={value} />), then all consumers are immediately notified and re-rendered

21
Q

If the consumer isn’t wrapped inside the provider, but still tries to access the context value (using useContext(Context) or <Context.Consumer>), then the value of the context would be the d_ v_ argument supplied to createContext(d_) factory function that had created the context.</Context.Consumer>

A

If the consumer isn’t wrapped inside the provider, but still tries to access the context value (using useContext(Context) or <Context.Consumer>), then the value of the context would be the **default value** argument supplied to createContext(**defaultValue**) factory function that had created the context.</Context.Consumer>

22
Q

context can hold:
g___ state
theme
application c______
a______-d user name
user s_____
preferred language
a collection of s_____s

A

context can hold:
global state
theme
application configuration
authenticated user name
user settings
preferred language
a collection of services

23
Q

The simplest way to pass data from a parent to a child component is when the parent assigns p____s to its child component

A

The simplest way to pass data from a parent to a child component is when the parent assigns props to its child component

function Application() {
  const userName = "John Smith";
  return <UserInfo userName={userName} />;
}

function UserInfo({ userName }) {
  return <span>{userName}</span>;
}
24
Q

The React Context API is s______less by default and doesn’t provide a dedicated method to update the context value from consumer components.

A

The React Context API is stateless by default and doesn’t provide a dedicated method to update the context value from consumer components.

25
The useReducer(reducer, _____) hook accepts 2 arguments: the reducer f____ and the initial s_____.
The useReducer(reducer, **initialState**) hook accepts 2 arguments: the **reducer function** and the **initial state**
26
The useReducer hook returns an array of 2 items: the c_____ state and the d_____ function.
The useReducer hook returns an array of 2 items: the **current state** and the **dispatch function**
27
An action object is an object that describes how to u_____ the state.
An action object is an object that describes how to **update** the state.
28
The d______ is a special function that dispatches an action object.
The **dispatch** is a special function that dispatches an action object. (Dispatching means a request to update the state.)
29
The dispatch is a special function that dispatches an a____ o_____.
The dispatch is a special function that dispatches an **action object**. (Dispatching means a request to update the state.)
30
The d_____ is a special function that dispatches an action object.
The **dispatch** is a special function that dispatches an action object. (Dispatching means a request to update the state.)
31
If you’re familiar with object-oriented programming, refs might remind you of instance fields—but instead of t___.something you write somethingRef.current.
If you’re familiar with object-oriented programming, refs might remind you of instance fields—but instead of **this.something** you write somethingRef.current.
32
The engine order telegraph is the d____ function, the commands are the a____ o____s, the engineers in the engine room are the r______ function, and the engine regime is the s____.
The engine order telegraph is the **dispatch** function, the commands are the **action objects**, the engineers in the engine room are the **reducer function**, and the engine regime is the **state**. https://dmitripavlutin.com/react-usereducer/#:~:text=The%20engine%20order%20telegraph%20is%20the%20dispatch%20function%2C%20the%20commands%20are%20the%20action%20objects%2C%20the%20engineers%20in%20the%20engine%20room%20are%20the%20reducer%20function%2C%20and%20the%20engine%20regime%20is%20the%20state.
33
> metaphor < The engine order telegraph helps separate the bridge from the engine room. In the same way the useReducer() hook helps separate the r_____ing from the s____ management logic.
The engine order telegraph helps separate the bridge from the engine room. In the same way the useReducer() hook helps separate the **rendering** from the **state** management logic.