Reputation: 103
I was wondering where does the property this.state
comes from when using React with TypeScript?
public constructor(props: any) {
super(props);
this.state = {
userName:"Code to html, one way -->",
password:""
};
}
We are not importing it in the super() call, so where does it comes from?
Upvotes: 0
Views: 400
Reputation: 53884
It comes from the internal implementation of React component which you inherit by extending the class React.Component
:
class MyComponent from React.Component {
// this.setState, this.state,
// lifecycle methods and more
}
See React.Component
and its instance properties.
Upvotes: 1
Reputation: 83527
where does it comes from?
It comes from the constructor. The line you are asking about is exactly where this.state
is initialized.
Upvotes: 0