J
J
jj swift2020-08-12 10:35:24
JavaScript
jj swift, 2020-08-12 10:35:24

How to pass data to functional components?

Good afternoon. I switch from class components to functional ones, using hooks. Now the question arose, how to actually pass data to the components?

After all, if I pass data directly to the component, then it will no longer be a presentational component, but too smart, because the presentational component implies reuse and predictability, container components in the form of classes come to the rescue, and the connection function with mapStateToProps and mapDispatchToProps (and in further compose for HOCs). At the moment, my App component is wrapped in a provider that provides a store. So how can I do it better? I just don't want to create containers.

If I pass all the data from one component to another using props, then soon everything will turn into a mess

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jj swift, 2020-08-12
@jfswift

I use useSelector as an alternative to mstp. But I can't implement mdtp yet.

T
t800zippygod, 2020-08-12
@t800zippygod

So if everything is wrapped in a provider, can useContext be used? Or am I missing something

A
Alexey, 2020-08-12
@AleksRap

Functional components may or may not be presentational. The logic is best isolated in custom hooks, then there will be no need to use extra wrappers in the form of hoc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question