Reactjs 当作为道具传递给功能组件时,反应功能未定义
我正在将主应用程序类中定义的函数传递给接受道具的功能组件。由于某种原因,我得到了一个错误,函数未定义。有人能帮我吗?我可能非常明显,但我想不出错误的原因Reactjs 当作为道具传递给功能组件时,反应功能未定义,reactjs,react-props,react-functional-component,Reactjs,React Props,React Functional Component,我正在将主应用程序类中定义的函数传递给接受道具的功能组件。由于某种原因,我得到了一个错误,函数未定义。有人能帮我吗?我可能非常明显,但我想不出错误的原因 //inside APP.js updateProgress = (val) =>{ this.setState({progress:val,currentid:val-1}).then(()=>{ console.log("progress",this.state.progress,"progress",th
//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>
))
)
}
//在APP.js内部
updateProgress=(val)=>{
this.setState({progress:val,currentid:val-1})。然后(()=>{
log(“progress”,this.state.progress,“progress”,this.state.currentid)
})
}
//内部功能组件脚本
const cooloptions=props=>{
返回(
props.options.map(o=>(
{o.title}
{o.description}
))
)
}
更改
onClick={updateProgress(props.mainprops.progress+1)}
到
谢谢这可以用来定义函数:)但是现在由于某种原因,当onclick处理程序运行时,我的进度道具未定义:(.我无法想象为什么,因为我能够从组件内部控制台.log()它??我很抱歉,这是道具钻削问题,我已经解决了。谢谢你的帮助!
onClick={()=>props.updateProgress(props.mainprops.progress+1)}