Getting Started Flashcards

1
Q

How can I make react render in an element in the HTML?

A

By simply calling ReactDOM.Render(
,
document.getElementById(“existing-elem-on-html”)
)

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

Why can I write HTML in a javascript file and it does not throw an error?

A

Because this is not HTML but JSX. Doesn’t throw an error because the react lib is imported in the javascript file.

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

What happens when you create a react component that is called starting with a lower case letter?

A

It will try to render the html directly (eg: function button…). Components needs to start with CAPITAL letter

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

How is a react hook declared?

A

by creating an array with a getter and one setter which receive an useState() method e.g
const [counter, setCounter] = userState();

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

What does use state method returns?

A

an array containing two elements which are destructured into an array.

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

How to inititalize the value of the getter part of the array?

A

By passing an argument to the useState(0);

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

What the onClick event expects to receive? Does it need to be in curly braces?

A

It expects to receive a POINTER to a method, NOT the execution of the method. Necessary to be within curly braces.. e.g:
… onClick={myFunc}… AND NOT myFunc()

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

Can I assign arrow functions to events such as onClick?

A

Yes… e.g:

onClick={() => console.log(‘hello’)}

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

In a summarized way: what is React Hooks?

A

It hooks a simple component into a state.

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

How to update the getter part of the array? Do we need to declare it?

A

By calling setState(). No need to declare it.

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

What is a React.Fragment? What is the shortcut to react fragment?

A

It is a way to group components together and avoid using divs. The shortcut for it is using empty tags <>

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

What does the props variable contains?

A

Key value pairs

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

What is the common saying about props and state?

A

immutable props, mutable state

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

Should we use loops and whiles in react? Is it a hard requirement?

A

No, we have to make it declarative by using map/filter/reduce. Not a hard requirement.

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

What is a good UI candidate to turn into a component?

A

Items that share data OR behavior

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

What is a good tip when naming react components? Why?

A

Naming them with two letters.. e.g: PlayNumber instead of Number. So that you won’t override javascript default objects.

17
Q

How much data should be passed to a component via props?

A

Just the necessary data. Do NOT take shortcuts and send the full list/array.

18
Q

What is a common react structure and order?

A

React hooks and states; then computations (functions)

19
Q

What is a reactEffect?

A

Is a method that is always executed when the component renders.

20
Q

What is a good practice when implementing the reactEffect method? How to do it?

A

To clean it up after its execution. It is possible cleaning it up by returning a lambda that clears the effect (e.g remove a previously created timer)

21
Q

What is a clever way to remount a React component?

A

By introducing and changing its key id to key + 1, then react will unmount and create a brand new component.

22
Q

What is a custom hook?

A

Is a method to group states and usually returns an array which will be destructured later on.

23
Q

What is the naming convention of a custom hook?

A

start the name using use… e.g: useGameState.

24
Q

What is a the two hard requirement for hooks?

A

Never use within loops and never conditionally create a hook

25
Q

Why using custom hooks?

A

To reduce complexity of the component mainly when it has to manage different states by itself, then therefore delegating the state changes and transitions.