Javascript 输入值不完整,为什么?

Javascript 输入值不完整,为什么?,javascript,reactjs,react-native,react-redux,Javascript,Reactjs,React Native,React Redux,所以,几乎每件事都按它应该的方式工作,问题是当我在输入中键入某个内容时,它不会完全更新redux状态。示例:如果我键入ABC,它将通过axios.post()将其发送到服务器,如AB。。。如果我输入啤酒,它将发送蜜蜂。。。它看不到最后一个字母,或者如果我在设备上选择自动完成文本,如果它是输入中的最后一个单词,它也看不到整个单词 有什么建议吗 提前谢谢 class AddressScreen extends Component { state = { usersNi

所以,几乎每件事都按它应该的方式工作,问题是当我在输入中键入某个内容时,它不会完全更新redux状态。示例:如果我键入ABC,它将通过axios.post()将其发送到服务器,如AB。。。如果我输入啤酒,它将发送蜜蜂。。。它看不到最后一个字母,或者如果我在设备上选择自动完成文本,如果它是输入中的最后一个单词,它也看不到整个单词

有什么建议吗

提前谢谢

  class AddressScreen extends Component {
      state = {
        usersNickOrName: "",
        usersAddress: "",
        usersPhoneNumber: ""
      };

      componentWillUpdate() {
    this.props.deliveryInfo(
      this.state.usersNickOrName,
      this.state.usersAddress,
      this.state.usersPhoneNumber
    );
  }

      onPressHandler = () => {


        let uid = this.props.uid;

        axios.post(
          `.../users/${uid}/info.json`,
          {
            nameOrNick: this.props.name,
            address: this.props.address,
            phoneNum: this.props.phoneNum
          }
        );
        this.props.navigator.pop();
      };

      render() {
        return (
          <View style={styles.container}>

            <AnimatedForm delay={100} distance={10}>
              <AnimatedInput
               onChangeText={text => {
                  this.setState({ usersNickOrName: text });
                }}
              />
              <AnimatedInput
                onChangeText={text => {
                  this.setState({ usersAddress: text });
                }}
              />
              <AnimatedInput
                onChangeText={text => {
                  this.setState({ usersPhoneNumber: text });
                }}
              />

              <Animated.View style={styles.buttonView}>
                <TouchableOpacity
                  style={styles.button}
                  onPress={this.onPressHandler}
                >
                  <Text style={{ color: "#fff" }}>Dodaj Info</Text>
                </TouchableOpacity>
              </Animated.View>
            </AnimatedForm>
          </View>
        );
      }
    }



    const mapStateToProps = state => {
      return {
        name: state.usersNickOrName,
        address: state.usersAddress,
        phoneNum: state.usersPhoneNumber,
        uid: state.userUid
      };
    };

    const mapDispatchToProps = dispatch => {
      return {
        deliveryInfo: (usersName, usersAddress, phoneNum) =>
          dispatch(deliveryInfo(usersName, usersAddress, phoneNum))
      };
    };

    export default connect(
      mapStateToProps,
      mapDispatchToProps
    )(AddressScreen);
类地址屏幕扩展组件{
状态={
usersNickOrName:“”,
usersAddress:“”,
usersPhoneNumber:“
};
componentWillUpdate(){
此.props.deliveryInfo(
this.state.usersNickOrName,
this.state.usersAddress,
this.state.usersPhoneNumber
);
}
onPressHandler=()=>{
设uid=this.props.uid;
轴心柱(
`…/users/${uid}/info.json`,
{
nameOrNick:this.props.name,
地址:this.props.address,
phoneNum:this.props.phoneNum
}
);
this.props.navigator.pop();
};
render(){
返回(
{
this.setState({usersNickOrName:text});
}}
/>
{
this.setState({usersAddress:text});
}}
/>
{
this.setState({usersPhoneNumber:text});
}}
/>
Dodaj信息
);
}
}
常量mapStateToProps=状态=>{
返回{
名称:state.usersNickOrName,
地址:state.usersAddress,
phoneNum:state.usersPhoneNumber,
uid:state.userUid
};
};
const mapDispatchToProps=调度=>{
返回{
deliveryInfo:(usersName、usersAddress、phoneNum)=>
分派(deliveryInfo(usersName、usersAddress、phoneNum))
};
};
导出默认连接(
MapStateTops,
mapDispatchToProps
)(地址屏幕);

您当前正在使用组件更新中的旧状态。改为使用下一个状态

componentWillUpdate(nextProps, nextState) {
  this.props.deliveryInfo(
    nextState.usersNickOrName,
    nextState.usersAddress,
    nextState.usersPhoneNumber
  );
}

请注意,componentWillUpdate已弃用,谢谢。使用nextState时,所有功能都非常好。。。关于折旧。。。我该怎么办?如何在没有componentWillUpdate的情况下实现同样的效果?@FatBoyGebajzla没有被否决,所以您可以使用它。@FatBoyGebajzla如果您决定使用
componentDidUpdate
来代替,那么您的状态将被更新,所以您应该再次使用
this.state.usersNickOrName
等。再次感谢您!改变了它,它工作得很好。干杯,伙计!