How to call a child component method from parent in React Native typescript

mohammad m

hello i'm new in React Native with typescript and in this example code i want to call testChild function from child Component in parentCall function in parent class and i dont know how to keep reference of each child component i cant change child component code how can i call testChild for each child component ?

class parent extends React.Component {
   public render(): JSX.Element {
        return (
         <child/>
         <child/>
               )
 public parentCall(): void{
   //call testChild for each Child component ??
}

}
class child extends React.Component {
 public render(): JSX.Element {
        return (
               <Text>Text</Text>
               )

 public testChild (): string{
   return Data ;
}
mohammad m

i solve my problem with Using res and define childRef field and with this code i store ref of child component in childRef

private onRef= (ref) => this.childRef= ref

and set it in child component

<child ref={this.onRef} />

now with childRef i can call its methods

childRef.testChild()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to call child component method from Parent Component on Scroll Back Of Tab View In React Native?

How to call React/Typescript child component function from parent component?

How to call child component's method from a parent component in React

Render child component or call child component's method from parent component and vice versa[React Native]

Call a method pass from parent component to child component in React

How to Call child function from parent component in React Native functional component?

How to use a method from grand Parent component to child component using props in react native?

How can I call method in child component from parent component?

How to call child component method from parent component with foreach

How to call a method in a child component from a parent component?

how to call child component method from parent component in blazor?

Calling a method of a parent component from child - React Native

How To Update State In Parent Component From Child Component In React Native?

How to get callback from child component to parent component in React Native

How to have a React child component call a function from a parent component

React Native: can't call a parent method from child

How do you call a parent function from a child component (with parameters) in react-native?

How to call the parent Method in child class component in react

React - Call parent method in child component

How to call method of child component from parent in EmberJS

ReactJS - how do I call a parent method from a child component?

How to call a method from child component to parent one?

Call method from parent to child via component

How can I call Child function from Parent Component in React

How to call a parent function from a child - react-native

How to call a parent function from the child in react native

React Native Opacity from Parent to Child Component

React Native - How to call a function from a child component?

How to call parent method from child in react-redux