Modern JavaScript and React

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/24

encourage image

There are no tags or description

Looks like no tags are added yet.

25 Terms

1
New cards
How do you destructure the title property from a book object in ES6?
const {title} = book;
2
New cards
What does .map do?
It transforms an array into a new array.
3
New cards
How do ES6 modules share code between files?
Modules explicitly export and import names.
4
New cards
How are React components named, and what do they return?
They are uppercase-named functions that return JSX.
5
New cards
What attribute names does JSX use instead of class and for?
className and htmlFor.
6
New cards
What are the JSX rules about tags and the root element?
Close all tags, and return one root element or a fragment.
7
New cards
What do props do in React?
They pass data down from parent to child.
8
New cards
What do list items need in React?
Stable keys.
9
New cards
How do you pass a click handler in React: onClick={handleClick} or onClick={handleClick()}?
onClick={handleClick}. Passing handleClick() would call it during render instead of on click.
10
New cards
What does useState give you?
An array of [value, setter].
11
New cards
What triggers a re-render when using useState?
Calling the setter.
12
New cards
When should you use the functional setter?
When the new value depends on the previous value.
13
New cards
How should you update arrays and objects in state?
Immutably, by creating a new array or object instead of changing the old one.
14
New cards
What two props make an input a controlled input?
value={title} and onChange={e => setTitle(e.target.value)}
15
New cards
When does useEffect run?
After rendering.
16
New cards
When does useEffect run with an empty dependency array []?
On mount. In development, Strict Mode can rerun mount effects.
17
New cards
When does useEffect run with a dependency array like [query]?
When query changes.
18
New cards
When does useEffect run with no dependency array?
After each render.
19
New cards
What can an effect return, and what is it used for?
A cleanup function, for listeners, timers, or pending requests.
20
New cards
How do you use async work inside useEffect?
Keep the effect callback synchronous and place the async work inside it.
21
New cards
Where should shared state live?
In the closest common parent. Props go down, callbacks go up.
22
New cards
Why avoid storing derivable state such as books.length?
It can be computed from existing state, so storing it risks it going out of sync.
23
New cards
What do client-side routes do?
They map URL paths to components.
24
New cards
What does Link do in React routing?
It navigates without a full page reload.
25
New cards
What does useParams do, and what type are the values?
It reads route segments. They are strings.