P
P
picka2021-11-27 01:58:18
JavaScript
picka, 2021-11-27 01:58:18

How to track props globally in React?

Task : in each component, it is necessary to styleprocess and return back when receiving a prop.

In Vue, I would write a global mixin that would simply keep track of the existence of a prop in the component, and pass its data to some computed, for further processing and return.

How can I implement this in React?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bevertax, 2021-11-27
@bevertax

You could use useContext for this if you are writing functional components.
In the Provider you pass style and setStyle, in each component you do const {style, setStyle} = useContext(...). And then call setStyle(newStyle) anywhere in the component, profit. You do not need to explicitly pass props to all components, this is evil

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question