【问题标题】:React Native, unable to update valueReact Native,无法更新值
【发布时间】:2021-01-23 05:37:08
【问题描述】:

我正在尝试更新 title 的值,但它没有更新值有人可以告诉我发生了什么 EditPost.js

class EditScreen extends Component {

  render() {
    return (
      <KeyboardAvoidingView
        behavior="position"
        keyboardVerticalOffset={Platform.OS === "ios" ? 0 : 100}
      >
        <Image
          style={styles.image}
          source={this.props.navigation.getParam("image")}
        />

        <View style={styles.detailContainer}>
          <AppTextInput
            value={this.props.navigation.getParam("title")}
            conChangeText={(text) =>
              this.props.navigation.setParams({ title: text })
            }
          />
          <AppTextInput value={this.props.navigation.getParam("des")} />
        </View>
        <AppButton
          text="Save"
          style={styles.button}
          onPress={() => {
            this.props.navigation.getParam("onEdit");
            this.props.navigation.goBack();
          }}
        />

home.js

 onEdit = (data) => {
    const newPosts = this.state.post.map((item) => {
      if (item.key === data.key) return data;
      else return item;
    });
    this.setState({ post: newPosts, editMode: false });
  };

请帮帮我...

【问题讨论】:

    标签: javascript reactjs react-native


    【解决方案1】:

    你有一个错字,为什么你不使用 useState 代替?

    <AppTextInput
                value={this.props.navigation.getParam("title")}
                conChangeText={(text) => --> typo, should be onChangeText ?
                  this.props.navigation.setParams({ title: text })
                }
    />
    

    【讨论】:

    • 有人更正了它,我也标记了他的答案:/ 无论如何 thnx 寻求帮助,我没有使用 useState bcoz 我没有使用函数库
    • 声明那是我猜的方式,但你的选择是祝你好运
    • 好吧,它让我可以更改文本,但在单击保存后不会更新它
    • 我将在主屏幕添加处理onEdit的功能
    猜你喜欢
    • 2020-02-15
    • 2021-09-01
    • 2019-03-27
    • 2022-01-22
    • 1970-01-01
    • 2021-05-06
    • 2021-11-15
    • 2017-01-14
    • 1970-01-01
    相关资源
    最近更新 更多