Best way of sending a variable to 2 different components in REACT

This is using REACT/NEXT.JS…

I am working on chat bot project which I need to send the input value to the display component, as well as communicating with a LangChain API… This means I would need to pass one variable to two different locations, then, get the response from the API and pass it to the display… and repeat the same process until conversation is done…

Now… I think I know how to do this… so far I think my best option would be using Redux which I am just getting information about in the last few days… BUT… What is your opinion on the best way to this ???

Your feedback is always awesome!

Redux is certainly an option for state management. It sounds like the behavior you are looking for could also be achieved without an additional dependency by storing the state at a higher level than where it’s needed and passing it down through props to the two components you need it in.

If you find you have to pass props from the state down often or multiple levels it could be good to use react context which would allow you to access at lower levels without prop drilling (passing down through many components)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.