javascript - react native + Redux : How to properly pass in props to action callers?

标签 javascript reactjs react-native redux react-redux

我进行了以下设置,其中所有方法都在构造函数中带有 .bind(this) 。因此,用户在输入中输入用户名和密码并更新状态,并且组件重新渲染并更新状态 this.props.usernamethis.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/

相关文章:

javascript - div 左右两侧的 float 按钮

javascript - 如何在 React 中显示具有不同键的 JSON?

javascript - 如何在react中获取json api中的图像?

javascript - React Native 中未处理的 promise 拒绝错误?

react-native - 海拔无法正常 react native

javascript - Scrimba.com 交互式 DOM 记录算法

javascript - 传递 Props 后的 ReactJS ComponentWillMount()

react-native - 在对面 react native View

javascript - jQuery 悬停事件同时影响两个不同的 Div(未嵌套)

javascript - 无法从选择框中选择项目/在输入字段中写入。我是否错误地处理了 'key'?