I am not trying to mutate props. I just want to have access to this.props in methods called in the constructor:
constructor(props){
super(props);
this.props = props; // CAN I? There is no errors or warnings
const filtered = this.filterValue(props.value);
this.state = {
value: filtered,
}
}
filterValue(value){
// here I need this.props.*
}
I know there is few ways to do it e.g. additional argument passed to filterValue, however I want it to be as simple as possible. I think that above code is quite intuitive, the question is: can I do it like this? React will override this.props anyway.
You can access props using this.props
in methods as described in the React.Component
documentation:
Instance Properties:
props
state
If you are curious, you can look at the source code of the ReactComponent
constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With