K
K
Kappy2018-11-29 10:15:50
JavaScript
Kappy, 2018-11-29 10:15:50

How to copy all props into state?

When I started learning react, I saw somewhere that all properties are copied to the state, in the constructor. Maybe I'm already confusing something, but is there such an entry: this.state = {props}?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-11-29
@KappyJS

There is one, but most likely you have seen this : this.state = {...props}
Then you won’t need to write this.state.props.foo, you can contact through this.props.foo.
In my opinion this is bad practice and should only be done in some very limited scenarios.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question