Reactjs 将数据从子组件传递到父组件获取错误prop.onCall不是函数

Reactjs 将数据从子组件传递到父组件获取错误prop.onCall不是函数,reactjs,Reactjs,我正在从函数子组件调用父函数 但是我得到了错误提示。onCall不是一个函数 当我使用console.log(props)时,道具也是未定义的 以下是父函数的: class Parent { construtor(props) { super(props); this.myFun = this.myFun.bind(this); } myFun = val = { console.log(val); } render

我正在从函数子组件调用父函数 但是我得到了错误提示。onCall不是一个函数

当我使用console.log(props)时,道具也是未定义的

以下是父函数的

class Parent {
    construtor(props) {
    super(props);
    this.myFun = this.myFun.bind(this);
    }
   
    myFun = val = {
    console.log(val);
    }
   
    render{
     return (
      <Child onCall={this.myFun} />
   
    )
    }
    }
const Child = props => {
   
    Handlefn = () => {
    props.onCall("hi");
    }
    }

你的应用程序中有大量的拼写错误。 试试这个

家长:

import React from "react";
import Child from "./Child";

export default class Parent extends React.Component {
  constructor(props) {
    super(props);
    this.myFun = this.myFun.bind(this);
  }

  myFun = val => {
    console.log(val);
  };

  render() {
    return <Child onCall={this.myFun} />;
  }
}
从“React”导入React;
从“/Child”导入子项;
导出默认类父级扩展React.Component{
建造师(道具){
超级(道具);
this.myFun=this.myFun.bind(this);
}
myFun=val=>{
控制台日志(val);
};
render(){
返回;
}
}
儿童:

import React from "react";

const Child = props => {
  const Handlefn = () => {
    props.onCall("hi");
  };

  return <h1 onClick={Handlefn}>Hi</h1>;
};

export default Child;
从“React”导入React;
const Child=props=>{
常数Handlefn=()=>{
道具。onCall(“hi”);
};
返回Hi;
};
导出默认子对象;

应该有一个箭头
myFun=val=>{…