Passing a function with parameters through props on reactjs

前端 未结 2 1528
青春惊慌失措
青春惊慌失措 2020-12-13 04:03

I have a function that comes from a parent all the way down to a the child of a child in a component hierarchy. Normally this wouldn\'t be too much of a problem, but I need

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 04:52

    An alternative and IMO more clean way to do it would be like this:

    class SomeComponent extends Component{
        myFunction = param => {
            console.log('do something: ', param);
        }
    
        render(){
         return (
           
    ) } } class ChildComponent1{ render(){ return (
    ) } } class ChildComponent2{ render(){ const { onClick } = this.props // destructure return () } }

提交回复
热议问题