I have a component with an injected Mobx store that has the following method:
constructor(props) {
super(props)
this.state = {
propertyChangeNotifications: true,
smsNotifications: false
}
}
updateNotifications = (type, value) => {
this.props.uiStore.updateProfile(type, value)
}
I am passing this method as a prop to a child component:
<ProfileDetails {...this.props.uiStore.profile} updateNotifications={()=> this.updateNotifications()} />
The child component has another method:
constructor(props) {
super(props)
// Get profile data from props
const {
propertyChangeNotifications,
smsNotifications,
person: {
fiscalId,
residentialAddress,
name,
lastName,
phoneNumber,
type,
email
}
} = props
// Set state according to props
this.state = {
name: name,
lastName: lastName,
fiscalId: fiscalId,
residentialAddress: residentialAddress,
phoneNumber: phoneNumber,
type: type,
email: email,
propertyChangeNotifications: propertyChangeNotifications,
smsNotifications: smsNotifications
}
}
handleCheckbox = (type) => {
this.props.updateNotifications(type, !this.state[type])
this.setState({
[type]: !this.state[type]
})
}
That I am passing to a semantic UI checkbox component:
<Checkbox toggle label="Notify via SMS " checked={smsNotifications} onChange={()=> this.handleCheckbox('smsNotifications')} />
Now what happens is that the Checkbox method (this.handleCheckbox) gets called with the correct argument. Then the this.props.updateNotifications method gets called with the correct arguments as well, but the function in the parent component (updateNotifications), gets called with undefined, undefined.
What am I doing wrong?