questions8 react Flashcards

1
Q

Explain React state and props.

A

React State:
the state controls the behavior of a component. Any change in the state leads to the re-rendering of the component. we can create the state with useState hook which will return state property and a set state function.

React Props :
Using props, we can pass data from one component to another. we can pass the props as a HTML attribute and the component accepts these props as an argument.
Props are read-only. They cannot be manipulated or changed inside a component.

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

Explain React Hooks.

A

Hooks are functions that let us “hook into” React state and lifecycle features from a functional component. They let us write components without class.
useState - to handle changeble data
useEffect - to implement all of the lifecycle hooks
useContext - to allow us to share data within it’s component tree
useRef - to create a mutable object
useMemo( ) - Saves the result of the executed function to the memory and next time when React will call this function with same arguments it will take it from the memory

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

techniques to optimize React app performance.

A
Using useMemo( ) -
 Saves the result of the executed function to the memory and next time when React will call this function with same arguments it will take it from the memory

Maintaining State Colocation - It is better to shift states which are less valuable to the parent component, to a separate component.

Lazy Loading -
It is a technique used to reduce the load time of a React app. Loads JS code needed only for your current page.

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

What are keys in React?

A

Keys are generally used for displaying a list of data coming from an API. A key is a special string attribute that needs to be included when using lists of elements.

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

How to pass data between react components?

A

Parent Component to Child Component (using props)
With the help of props, we can send data from a parent to a child component. Also can use destructuring with props.

Child-to-parent components use callback props.

Child to child - Child-to-parent through callback -> store in parent state -> parent to another child through props

useContext let you ignore intermediate components between context component and target component

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