this.props.getAddNewObj不是reactjs中的函数
我将两个函数从父组件传递到子组件,一个函数工作正常,但另一个函数出错 this.props.getAddNewObj不是函数 请任何人帮助我this.props.getAddNewObj不是reactjs中的函数,reactjs,Reactjs,我将两个函数从父组件传递到子组件,一个函数工作正常,但另一个函数出错 this.props.getAddNewObj不是函数 请任何人帮助我 import ChildComModal from './modal'; class ParentCom extends Component{ handleModal=()=>{ this.refs.modalRef.handleModal() } getAddNewObj=(event)=>{ this.setState({
import ChildComModal from './modal';
class ParentCom extends Component{
handleModal=()=>{
this.refs.modalRef.handleModal()
}
getAddNewObj=(event)=>{
this.setState({newObj:event})
}
getNewEditedObj=(event)=>{
this.setState({newObj:event})
}
render(){
return(
<React.Fragment>
<ChildComModal
ref="modalRef"
getAddNewObj={this.getAddNewObj}
getNewEditedObj={this.getNewEditedObj}
/>
<Button onClick={this.handleModal}>Open Modal</Button>
</React.Fragment>
)
}
}
export default ParentCom ;
class ChildCom extends Component{
handleModal=()=>{
this.setState({isOpen:true})
}
habdleAdd=(e)=>{
this.props.getAddNewObj(e)
}
handleEdit=(e)=>{
this.props.getNewEditedObj(e)
}
}
export default ChildCom;
从“/modal”导入ChildComModal;
类ParentCom扩展组件{
手足动物=()=>{
this.refs.modalRef.handleModal()
}
getAddNewObj=(事件)=>{
this.setState({newObj:event})
}
GetNewEditeDB=(事件)=>{
this.setState({newObj:event})
}
render(){
返回(
开放模态
)
}
}
导出默认的ParentCom;
类ChildCom扩展组件{
手足动物=()=>{
this.setState({isOpen:true})
}
habdleAdd=(e)=>{
this.props.getAddNewObj(e)
}
handleEdit=(e)=>{
this.props.getNewEditedObj(e)
}
}
导出默认的ChildCom;
你能在codeSandbox中创建你的代码示例吗?你正在将道具传递给
你正在ChildCom
中使用这些道具,显示类ChildComModal
你确定你正在呈现正确的组件吗?我认为你把道具传递给了错误的组件@MuhammadHaseeb在codesandbox工作。那我就不会在我的应用程序中犯错误了component@ssk组件名称不是问题,有“GetNewEditedBj”函数正在调用另一个“getAddNewObj”函数,只得到一个错误