为了账号安全,请及时绑定邮箱和手机立即绑定

React Native,无法更新值

React Native,无法更新值

Smart猫小萌 2023-04-27 17:23:31
我正在尝试更新 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();          }}        />主页.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 });  };有人可以帮我吗...
查看完整描述

1 回答

?
莫回无

TA贡献1865条经验 获得超7个赞

你有错字,无论如何你为什么不使用 useState 呢?


<AppTextInput

            value={this.props.navigation.getParam("title")}

            conChangeText={(text) => --> typo, should be onChangeText ?

              this.props.navigation.setParams({ title: text })

            }

/>


查看完整回答
反对 回复 2023-04-27
  • 1 回答
  • 0 关注
  • 98 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信