G
G
Georgy Kuznetsov2022-01-07 17:51:31
React
Georgy Kuznetsov, 2022-01-07 17:51:31

Is it worth it in a React application to try to get the state of another in one component, and is this an illiterate move?

Suppose there are two components, the purpose of one (let's call A) is to display a news feed (several structural elements of the type "name of the news + part of the content") the purpose of the other (let's call B) is to display the news selected by the

user data from the state of component A?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yustas Alexu, 2022-01-08
@JoeSmith3100

If the components are on different routes, that is, when component B is displayed, the page URL or its hash changes, then this solution will not work. For example, when the user navigates to component B via a link, the state of component A does not exist and component B does not receive the necessary data.
If both components are on the same route, then this is a completely normal solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question