E
E
eugenedrvnk2020-04-25 18:28:25
React
eugenedrvnk, 2020-04-25 18:28:25

How to refer to a component method through ref?

In vue, sometimes there were situations when there was something like this structure.

<div>
    <SomeComponent ref="someComp"}/>
</div>

mounted() { this.$refs.somComp.someMethod() }


And it was necessary to call the someMethod method from the parent component (in which someComponent is rendered). As a result, the call via this.$refs.someMethod() worked and everything was successfully called. What is the approach to do this in React?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-04-25
@abberati

No. Components hide their logic from their parents, and parents don't have to know anything about the implementation of their children. From top to bottom, you can descend data, and from top to bottom, you can pass events. That's all there is about communication between components.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question