反应组件交互和全局状态更改

反应组件交互和全局状态更改

本文介绍了反应组件交互和全局状态更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对React很新,只是尝试一下。我想知道什么是一些常见的模式,或者用于处理组件之间通信的内置函数库。例如,我有输入组件和列表组件,它根据输入控制器中的内容从服务器更新。想想一个自动完成框。由于组件具有表示逻辑,如果两者不能另外怎么办?它们位于页面的不同部分,因此有两个不同的控制器。

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.

此外,如果我有一个通过Ajax工作的登录/注销按钮怎么办?我想在页面上的许多不同组件对登录/注销操作做出反应,重新配置它们自身符合全局已记录状态以及从服务器为已登录的特定用户检索的数据。

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.

React对这些变化做出反应的最佳方式是什么?谢谢

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

推荐答案

你应该结帐和。
它有点像酒吧/子系统,但没有pub / sub系统的问题。优点是所有事件都在一个方向流动,这使得体系结构更加简单和可扩展。

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.

这篇关于反应组件交互和全局状态更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:47