Event binding - Dan Abramov Conference talk

https://youtu.be/dpw9EHDh2bM?t=1172

After watching the video, answer the following questions:

  1. How do we store state in class-based components?
  2. How do we store state in functional components?
  3. What is the return value of a useState call?
1. How do we store state in class-based components?
  • State is stored as properties in the class variable this.state (can have multiple)
  • The initial state can be set in the constructor by directly setting this.state
  • Subsequent updates to state is done via the function this.setState()
2. How do we store state in functional components?

By declaring state variables with useState(name)

3. What is the return value of a useState call?
  • useState() returns 2 variables the first is reference to the value (a getter?) and second a setter function for updating the value.
  • need separate calls to useState for each property
  1. How do we store state in class-based components?

We use this.state and this.setState
2. How do we store state in functional components?
We can use useState() with hooks to make an before and after event
3. What is the return value of a useState call?
The return value is the current state after the change

1 Like

1, How do we store state in class-based components?
we store the state variable in this.state object and we change it is by calling this.setState.
2, How do we store state in functional components?
we use react state hook to store the states.
3, What is the return value of a useState call?
It returns a pair of values: the current state and a function that updates it.

1. How do we store state in class-based components?
State is stored as an object and we use this.state within class-based components.

2. How do we store state in functional components?
In functional components, we use hooks (ie useState) to store state.

3. What is the return value of a useState call?
The useState call returns the current state and a function which will update it.

1. How do we store state in class-based components?
We store ‘state variable’ as a property of the object this.state and we change it with this.setState()

2. How do we store state in functional components?
By declaring it with
const [name, ... ] = useState('oldValue')
and specifying the initial value.

3. What is the return value of a useState call?
The useState call returns :

  • a variable that point to the state value :thinking: … or rather a variable that receives a value from an object that points to the different values of the state
  • and a function which allow to switch the old value to the new one which it will receive in parameter
	1. How do we store state in class-based components?
		i. in props state
	2. How do we store state in functional components?
		i. const variable declared with useState
	3. What is the return value of a useState call?
		i. value of current state and a setter function for the state

1.How do we store state in class-based components?
By using this.state and .setState
2.How do we store state in functional components?
Using useState allows the developer to have state variable in functional components.
3.What is the return value of a useState call?
It returns a pair of values: the current state and a function that updates it!