【发布时间】:2017-08-30 13:50:19
【问题描述】:
import ImageGallery from 'react-image-gallery'
methodOne(){
return (<div><ImageGallery /></div>)
}
methodTwo(){
return (<h1>{this.methodOne()}</h1>)
}
render() {
return(
<AnotherCommonComponent methodTwo={this.methodTwo} />
)
}
当我尝试将 methodTwo 作为 prop 传递给另一个组件时,我得到了未定义的 methodOne。奇怪的是,当我直接渲染时,我可以让 methodOne 工作
render() {
return(
<methodTow />
)
}
是因为this 的问题吗?我什至尝试过
methodOne = () => {
return (<h1>h1 here</h1>)
}
没有任何效果。
【问题讨论】:
标签: javascript reactjs