账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react更新状态问题.
    29
    0

    请问这种更新方法会不会有什么问题

    //子组件方法更新:
    addItem=()=>{
        this.props.editList.push(1)
        this.setState({})
    }
    removeItem=()=>{
    this.props.editList.splice(0,1)
    this.setState({})
    }
    ...
    //父组件:
    class{
    ...
    render(){
     return <Child editList={this.state.list}>
    }
    }
    

    我在重写代码时候,有很多这种修改props写法,当时就是不想让父组件挂太多方法像这样(<Child editList={this.state.list} addItem={this.addItem} ... ...>),所以把更新操作写在子组件内部,实际上好像很少有这样写法,虽然没报错,但是不知道这种写法会不会有什么问题?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 黄昏老枪 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部