React Flashcards

1
Q

React.createElement

A

lets you create a React element. It serves as an alternative to writing JSX.

import { createElement } from 'react';

function Greeting({ name }) {
  return createElement(
    'h1',
    { className: 'greeting' },
    'Hello'
  );
}

JSX calls createElement for you

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

ReactDOM.createRoot

A

lets you create a root to display React components inside a browser DOM node.

import { createRoot } from 'react-dom/client';

const domNode = document.getElementById('root');
const root = createRoot(domNode);

React will create a root for the domNode, and take over managing the DOM inside it. After you’ve created a root, you need to call root.render to display a React component inside of it:

root.render(<App />);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

ReactDOM.createRoot vs ReactDOM.render

A

ReactDOM.createRoot is a new API as of React v18. The old ReactDOM.render is still available (and deprecated) but it’ll render your app in “legacy” mode which won’t use all the fun new features packed into React v18

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

one-way data flow

aka one-way binding

A
  • In React, each state is owned by one component
  • the changes made on the state of the component will only affect the children and not the parents or siblings.

keeps everything modular and fast.

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

Explain JSX

A

JSX converts HTML tags into react elements (by calling React.createElement)

makes it easier to write React applications.

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

Explain what React does in response to a user input

e.g. User enters something in form input

A

when you type in the input, React detects that a DOM event happens. When that happens, React thinks something may have changed so it runs a re-render. Providing your render functions are fast, this is a very quick operation. It then diffs what’s currently there and what its render pass came up with. It then updates the minimum amount of DOM necessary.

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

Explain the following react hook:
const [location, setLocation] = useState("Boston")

A
  • location: piece of state that you can track
  • setLocation: function that will update that piece of state
  • “Boston”: the initial value that location will be set to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain the following react hook in terms of ES6 destructuring:
const [location, setLocation] = useState("Boston")

A
// useState returns an array
const locationHook = useState("Boston")
const location = locationHook[0]
const setLocation = locationHook[1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are keys important for array items in React

A

So React knows if any items in the array switched places. Then React can make the correct updates to the DOM tree.

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

What are hooks in React

A

Hooks are functions that let you “hook into” React state and lifecycle features from function components. Hooks don’t work inside classes — they let you use React without classes.

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

What is the Effect Hook in React

useEffect()

A

adds the ability to perform side effects from a function component. It 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

What does React Router do

A

keeps your UI in sync with the URL

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

useParams

React Router

A

The useParams hook is how you get params from React Router.

It used to be through the props but now they prefer this API.

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

What is React Query

A

easy to use data-fetching libary for React

handles fetching, caching, etc…

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

props & destructuring

A

React component functions accept a single argument, a props object

function Avatar(props) {
  let person = props.person;
  let size = props.size;
  // ...
}

Destructuring - this is same as above:

function Avatar({ person, size }) {
  // ...
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do curly braces do when inside JSX

A

let you “escape back” into JavaScript

17
Q

explain this syntax:
style={{}}

A
  • not a special syntax
  • just a regular {} object inside the style={ } JSX curly braces.
  • You can use the style attribute when your styles depend on JavaScript variables.
18
Q

React DOM

A

React’s library to talk to web browsers