Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React component interaction and global state changes

I'm very new to React, just experimenting with it. I'd like to know what are some common patterns, or libraries o built-ins for handling communication among components. For example, I have am input component and a "list" component that updates from the server according to what is in the input controller. Think of an autocomplete box. Since components have presentation logic, What if the two can't be "besides"? They're in different parts of the page and hence two different controllers.

Also, what if I have a login / logout button that works via Ajax? I imagine a lot of different components across the page reacting to the login / logout action reconfiguring themselves accord to a global "logged" state and the data retrieved from the server for the specific user that has logged in.

What is the best way that React "reacts" to those changes? Thanks

like image 330
pistacchio Avatar asked Nov 01 '22 10:11

pistacchio


1 Answers

You should checkout Flux and Dispatcher. It's kind of like a pub/sub system but without the problems of a pub/sub system. The advantage is that all events flow in one direction which makes the architecture much simpler and scalable.

like image 70
Wim Mostmans Avatar answered Nov 07 '22 23:11

Wim Mostmans