Reputation: 1993
I have a class like the one below, I added a new parameter in mapStateToProps, and I can see it when rendering. I don't know how to pass it to the onClick method. Any Idea? I prefer not to pass it directly when I call the function, there are other parameters already accessible that are not passed directly.
class A extends Component{
static propTypes = {
myValue: PropTypes.string.isRequired
}
onClick = (param1, param2) => {
>>>I want to access myValue here<<<
}
render() {
const { myValue } = this.props
return (
<MyCompoment
onClick={this.onClick}
>
)
}
}
const mapStateToProps = (state, props) => ({
myValues: getMyValue(state),
})
Upvotes: 0
Views: 73
Reputation: 4380
You can access it like:
onClick = (param1, param2) => {
const test = this.props.myValues;
}
or like render method:
onClick = (param1, param2) => {
const { myValue } = this.props;
}
Upvotes: 1