[作为函式传递给功能组件时,未定义反应功能

问题描述 投票:1回答:1

我正在将在主应用类中定义的函数传递给可以接受道具的功能组件。由于某种原因,我收到函数未定义的错误。有人可以帮我吗?我可能不是很明显,但我想不出错误的原因。

//inside APP.js

updateProgress = (val) =>{
    this.setState({progress:val,currentid:val-1}).then(()=>{
      console.log("progress",this.state.progress,"progress",this.state.currentid)
    })
  }

<mycomponent updateProgress={this.updateProgress} mainprops={this.state}/>

// inside functional component script

const cooloptions = props => {
  return (

    props.options.map(o => (
      <div key={o.key}>
        <label htmlFor={o.key}>
            <strong>{o.title}</strong>
            <p>{o.description}</p>
        </label>
        <input id={o.key} name={o.name} onClick={updateProgress(props.mainprops.progress+1)} type="radio" />
      </div>
    ))
  )
}
reactjs react-props react-functional-component
1个回答
2
投票

更改

onClick={updateProgress(props.mainprops.progress+1)}

onClick={()=>props.updateProgress(props.mainprops.progress+1)}
© www.soinside.com 2019 - 2024. All rights reserved.