Reputation: 411
I simply made a state object since there was no need of constructor. I accessed props in that state object as this.props
, so here in this state object I am able to access the props using this
keyword. Can someone state any reason for not using it the current way and defining a constructor.
state={visibility: this.props.visibility}
got following result from babel.repl
Upvotes: 0
Views: 34
Reputation: 411
I found the answer in, it makes no difference if we initialise in constructor or in class https://michalzalecki.com/react-components-and-class-properties/
Upvotes: 1