I
I
Igor2020-05-03 10:46:04
React
Igor, 2020-05-03 10:46:04

Why are refs needed in ReactJS?

Not so long ago, I undertook to study ReactJS, but I ran into a misunderstanding. What are refs for ?


However, there may be situations where you need to imperatively change a child element, bypassing the normal data flow.
clipping from office documentation

  1. Why might you need to bypass the main data stream (if I understand correctly, we are talking about props)?
  2. Why can't I use context for this?

Please explain with an example.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Alexandrovich, 2020-05-03
@loonny

In order to access the props of the child component from the parent or the state of the child component from the parent, or call the method of the child component from the parent.

B
Bohdan Petrov, 2020-05-03
@mindyourlifeguide

I think it will be faster for you to google than to write to someone.
But if anything, then here it is .

V
Vlad_Murashchenko, 2020-05-05
@Vlad_Murashchenko

Don't use ref if you can do without it. This feature should be used as infrequently as possible. After a while, you yourself will understand why this is needed, but for now, just skip and focus on the philosophy of react chapter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question