How to traverse to traverse props in the state?

How to fix the props in the state?
I use the syntax class field and make it so:
state = {
 text: this.props.text
};

Then we heard from one pipeline that is wrong, like "this needs to be inside a non-static method" and needs to be initialized in the constructor. Is he right? state what side this is, it's not a method?
April 4th 20 at 13:02
4 answers
April 4th 20 at 13:04
Solution
Then we heard from one pipeline that is wrong, like "this needs to be inside a non-static method" and needs to be initialized in the constructor. Is he right?


All right. But he does not understand that such a record is not static, and after transpla will appear in the designer.
I should add that it's syntactic sugar, called class property initializer to not write 100500 times
this.something = something in the constructor of the class; not to react, and Babel. - Jailyn87 commented on April 4th 20 at 13:07
@Jailyn87that this Babel know, didn't know what he compiled - patsy_Waters commented on April 4th 20 at 13:10
@patsy_Waters, babel repl exemplary exhaust (only there uncheck env preset, because it is the link :() - Raoul.Bergstr commented on April 4th 20 at 13:13
April 4th 20 at 13:06
constructor(props){
super(props)
this.state={
 text: this.props.text
}
}

this is as it should be. But if your method works then why not use it ?))))
Why "must"? The question implies the presence of arguments. Just works and why not to use the right approach should be done qualitatively, not just to work - patsy_Waters commented on April 4th 20 at 13:09
April 4th 20 at 13:08
Generally the classes themselves, there are Hooks React. There is no need to write this in principle.
Who said this statement? - patsy_Waters commented on April 4th 20 at 13:11
April 4th 20 at 13:10
Do the logic you need to use the props directly in state granitse the only thing that can change in the process, the component with the same props
There are times when it is forwarding the initial state of the props - patsy_Waters commented on April 4th 20 at 13:13

Find more questions by tags React