我进行了以下设置,其中所有方法都在构造函数中带有 .bind(this) 。因此,用户在输入中输入用户名和密码并更新状态,并且组件重新渲染并更新状态 this.props.username
和this.props.password
得到传承。然后我想将它们传递给一个名为 this.props.registerUser()
的 Action 创建者。单击“注册”按钮后。
所以我想知道,将新更新的 Prop 传递给 Action 创建者的正确做法是什么?
例如
是_handleRegister(this.props.username, this.props.password)
吗?然后this.props.registerUser(this.props.username, this.props.password)
?或者简单地this.props.registerUser(this.props.username, this.props.password)
?或者 this._handleRegister(this.props.username, this.props.password)
的组合和以前?
_handleRegister() {
this.props.registerUser()
}
render() {
return (
<View>
<TextInput
placeholder={'Username'}
onChangeText={...}
value={this.props.username}
/>
<TextInput
placeholder={'Password'}
onChangeText={...}
value={this.props.password}
/>
<TouchableHighlight onPress={this._handleRegister}>
<Text>Register</Text>
</TouchableHighlight>
</View>
)
}
}
谢谢
最佳答案
您不需要将参数传递给_handle Register
_handleRegister() {
const { username, password, registerUser } = this.props;
registerUser(username, password);
}
额外提示:您可以通过执行以下操作来跳过 return 关键字:
render() (
<View>
...
</View>
)
关于javascript - react native + Redux : How to properly pass in props to action callers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39631092/