F
F
Faraday_222019-01-19 19:08:23
React
Faraday_22, 2019-01-19 19:08:23

Is it possible to call a method on a child component from a parent?

For example, there is a parent component that returns children through this.props.childern
Is it possible to somehow call the method that is described in the child component from the method of the parent component?
For example, in the method of the Wrap component, call the method of the Item component

<Wrap>
    <Item/>
</Wrap>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor, 2019-01-20
@polyak-888

I think no. You can forward a method from a parent component to a more nested (child) component via props. I believe that you can solve the problem either by using Redax. Or wrap the components you specified in another one and it will be a parent for them, write a method in it and pass it through the props.
If, of course, I understood the question correctly. Here is an article about this https://habr.com/en/post/436702/

A
abberati, 2019-01-20
@abberati

Maybe you are doing something wrong? In my experience, there were no such situations - most likely you can solve your problem without crutches, having risen to a higher level.
Describe the situation more broadly - there is a solution without calling child methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question