Skip to Content
React学习手册
book

React学习手册

by Alex Banks, Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from React学习手册
208
9
9
-
1
:组件树中的数据流传递
显式传递
Store
首先,将
Store
集成到
UI
中最合乎逻辑的做法是显式地将它作为属性在组件树中向下传
递。该方法很简单,对于只包含少量嵌套组件的小型应用程序效果非常好。
接下来看看如何将
Store
集成到颜色管理器程序中。在
./index.js
文件中,我们将会渲染
一个
App
组件并传递
Store
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
import storeFactory from './store'
const store = storeFactory()
const render = () =>
ReactDOM.render(
<App store={store}/>,
document.getElementById('react-container')
)
store.subscribe(render)
render()
这就是
./index.js
文件中的内容。在这个文件中,我们使用
storeFactory
创建了一个
Store
,并将
App
组件渲染到了
DOM
文档中。当
App
组件渲染完毕后,
Store
会作为属性
React Redux
209
传递给它。每次
Store
发生变化后,
render
函数都会被触发执行,这样就可以使用新的
State
数据高效地更新
UI
了。
现在已经将 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React快速上手开发

React快速上手开发

Stoyan Stefanov
流畅的Python

流畅的Python

Luciano Ramalho
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787519814236