从子无状态类组件访问父无状态功能组件的更新道具

时间:2018-06-21 13:15:40

标签: javascript reactjs react-native react-redux

子组件

export class child extends Component {
  buttonclick() {
    const { pin } = this.props
    if (pin === null) {
      add().then(result => {
        updatePin(result.data)
      })
    } else {
      remove(pin.id).then(result => {
        updatePin(result)
      })
    }
  }

  render() {
    const { pin } = this.props
    const label =
     pin === null
        ? 'yes'
        : 'no'

    const icon =pin === null ? 'yes' : 'no'

    return (
      <div>
          <Button
            icon={icon}
            label={label}
            onClick={() => this.buttonclick()}
          />
      </div>
    )
  }
}

父组件(无类组件)

    const parent= props =>{
        const { pins = []} = props
        const { pin } = Data
    }
    const updatePin = result => {
    // here iam updating the pin
   }
      const renderchildComponent=()=>{
    return(
        <div>
         <ChildComponent
                pin={pin}
                updatePin={result => updatePin(result)}
              />
       </div>
    )
    }

在上面的代码中,该引脚在父组件中进行更新,但是如何在每次单击按钮时都将其传递给子组件而不刷新页面。请帮我解决这个问题

0 个答案:

没有答案
相关问题