Answer the question
In order to leave comments, you need to log in
Passing value from one component to another, ReactJs?
Hello! Can you please tell me if it is allowed in Reactjs to pass values from one component to another via a global variable? In the example, the global variable color1. codepen.io/juniorCh/pen/ZOqLov I would be grateful for any alternative solution. I am also interested in how you would style the inputs, that is, there is an input with value=red and you need to have the same background.
Thanks in advance for help)
Answer the question
In order to leave comments, you need to log in
1) context
At the main component, for example, App (or you can create a wrapper component, HOC), a childContext is given, in which the necessary parameters are passed.
2) we store the config in a separate file and connect it where necessary
export default {
color: 'red'
}
:root {
--color: red;
}
input {
color: var(--color);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question