0

how can I call a parent components methods from child or visa versa.

I'm using reactjs and typescript in spfx webpart.

Or should I use helper classes to call methods of another classes from anywhere?

Thanks in advance.

0

there are very few information you give but I guess your problem will be solved by giving CallBack functions to your ChildElement like this:

parentElement.ts

public render(){
    ...
        <MyChildComponent 
            optionsA={this.props.OptionsA} //give some properties to your Component
            optionsSelected={this.optionsSelected.bind(this)} //give a CallBack
         />
    ...
}

...

private optionsSelected(selection){
// DO SOMETHING
}
    ...

childElement.ts

public render() {
...
    <myChildDropDown
       onChanged={(event) => this.props.optionsSelected(event)}
     />
...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.