React Flashcards

1
Q

What is Webpack?

A

It is a static module bundler for modern JavaScript applications (takes all the files and bundles them into one for your application)

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

What is the advantage of using Webpack (or a similar bundler)?

A

It internally builds a dependency graph from one or more entry points and then combines every module your project needs into one or more bundles, which are static assets to serve your content from.

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

What is Babel

A

Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.

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

What is the advantage of using Babel (or a similar transpiler)?

A

So you can work on old applications using newer code/methods

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

What is React?

A

React is a way to let you build user interfaces out of individual pieces called components.

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

What is a React element?

A

A React element is what gets returned from components (a custom written DOM element)

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

How do you mount a React element to the DOM ?

A

Attaching/Appending/Rendering

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

What is JSX?

A

JSX is an extension to the JavaScript language syntax which provides a way to structure component rendering using syntax familiar to many developers commonly used in React

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

How does React use JSX to render components?

A

const root = ReactDOM.createRoot(document.getElementById(‘root’));
root.render(

<React.StrictMode>
<ComponentName></ComponentName>
</React.StrictMode>

);

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

What is a React component?

A

Independent and reusable bits of code

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

How do you define a component in React?

A

With a capital letter, and return a jsx

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

How do you mount a component to the DOM (or “render” a component)?

A

By attaching it to the root. calls the function when it sees it wrapped in <>. Takes the result of calling the function and puts it in the DOM.

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

What are props in React?

A

A type of object where the value of attributes of a tag is stored

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

How do you use props in a component?

A

By passing them as an attribute and setting their value as the value of the attribute

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

How do you write JavaScript expressions in JSX?

A

Within curly braces

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

How to you pass an event handler to a React component?

A

As an argument/prop

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

What is the naming conventions for event handlers?

A

Event names are written in camelCase

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

What are some custom event handler props a component may wish to define?

A

onClick, onSubmit, onChange

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

What is the naming convention for custom event handler props?

A

Usually with the prefix on*

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

What is an eventHandler?

A

A function that occurs when something is activates it

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

What is an eventHandler?

A

A function that occurs when something is activates it

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

What are hooks in React?

A

useState or any other function starting with “use”. Hooks are special functions that are only available while React is rendering.

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

What are “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)

A

Only call hooks at the top level. Only call hooks from react functions. Call hooks from react function components. Call hooks from custom hooks.

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

What is the purpose of state in React?

A

To contain data or information about the component

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

Why can’t we just maintain state in a local variable?

A

It would be gone after it gets re-rendered

26
Q

What two actions happen when you call a state setter function?

A

It will update the variable and trigger react to render the component again

27
Q

When does the local state variable get updated with the new value?

A

After useState has been called

28
Q

How do controlled components differ from uncontrolled components?

A

Controlled components refer to components that have their state and behavior controlled by the parent component

29
Q

What are some advantages of using uncontrolled components?

A

You don’t have to declare state

30
Q

Which style do you prefer?

A

controlled

31
Q

What two props must you pass to an in put for it to be “controlled”?

A

useState

32
Q

What are some popular npm packages for creating forms in React?

A

react final form

33
Q

What are some advantages of using controlled components?

A

You can have a live search bar. You do things with that individual value

34
Q

When would we want to create a list of React components?

A

Whenever you need to have lists coming from a database or from a user

35
Q

Why is it important for React components to be data-driven?

A

So that the only thing that changes is the data

36
Q

Where in the component code would a list of React components typically be built?

A

Inside the function body

37
Q

What Array method is commonly used to create a list of React components?

A

.map

38
Q

Why do components in a list need to have unique keys?

A

Because react need to keep track incase they want to reorder or remove

39
Q

What is the best value to use a “key” prop when rendering lists?

A

A number, must be in the outer most element

40
Q

What are two ways React components can interact?

A

Passing properties from a parent component to children components, and by responding Events from children components

41
Q

How can multiple React components share state?

A

By removing state and passing components to their closest parent and then passing it down to them via props

42
Q

What are the steps to “lift state up”?

A
43
Q

When would you want to lift state up?

A
44
Q

When is a component “mounted” to the DOM?

A
45
Q

What is a React Effect?

A
46
Q

When should you use an Effect and when should you not use an Effect?

A
47
Q

When do Effects run?

A

After the page renders, ands runs as things change

48
Q

What function is used to declare an Effect?

A

useEffect

49
Q

What are Effect dependencies and how do you declare them?

A

When an effect should run and declare them in the array

50
Q

Why do you want to clean up from an Effect?

A
51
Q

How do you clean up from an Effect?

A
52
Q

When does the cleanup function run?

A
53
Q

What is the purpose of React “context”?

A

Allows you to share information to any component, by storing it in a central place and allowing access to any component that requests it. (must be a child)

54
Q

What values can be stored in context?

A

Information to any component

55
Q

How do you create context and make it available to the components?

A

import { createContext } from ‘react’;
export const AppContext = createContext();

56
Q

How do you access the context values?

A

Through props with the help of useContext method in React

57
Q

When would you use context? (in addition to the best answer: “rarely”)

A

When building large applications

58
Q

What is React custom hooks?

A

Reusable functions that a React JS software developer can use to add special and unique functionality to the React applications

59
Q

When are custom hooks useful? When are they not required?

A

When you need to reuse more than a few times

60
Q

What is the syntax (or naming convention) for writing a custom hook?

A

Starts with the word “use” and may call other Hooks

61
Q

How do you call a custom hook?

A

Same way as a normal hook

62
Q

When do custom hooks execute?

A

Every time the component is rendered.