親コンポーネントに渡されるばかりではありません子コンポーネント:ReactJS onClickの引数は、私は次のメソッドを持って注入さMobxストアでコンポーネントを持って
<ProfileDetails {...this.props.uiStore.profile} updateNotifications={()=> this.updateNotifications()} />
子コンポーネントは、別の方法があります。
<Checkbox toggle label="Notify via SMS " checked={smsNotifications} onChange={()=> this.handleCheckbox('smsNotifications')} />
何happe:私は、意味UIのチェックボックスコンポーネントに渡しています
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]
})
}
nsは、Checkboxメソッド(this.handleCheckbox
)が正しい引数で呼び出されることです。次にthis.props.updateNotifications
メソッドも正しい引数で呼び出されますが、親コンポーネントの関数(updateNotifications
)はundefined
,undefined
で呼び出されます。
私は間違っていますか?