2015-12-16 40 views
1

阵营文档声称render()方法是this.propsthis.statehttps://facebook.github.io/react/docs/component-specs.html)的函数:“this.props”和“this.state”的功能是什么?

render()方法声明写成的this.propsthis.state功能。该框架保证UI始终与输入保持一致。

这是什么意思? this.propsthis.state的对象是肯定的,而不是功能:

this.props === Object {} 
this.state === Object {data: Array[0]} 

那么如何理解?

回答

2

是什么意思的是,概念render()this.propsthis.state功能。用这种方式想想,this.propsthis.state的结果相同render()应该总是一样的。

它不是像render(props, state)那样写的,但从概念上讲,这是人们应该考虑组件的方式!

0

Component Specs

当所谓的[渲染器],它应该检查this.props和this.state并返回 一个子元素。

如果render()被放置在组件的外面,它看起来像:

function render(props, state)

由于propsstate是所有render()需要呈现。

1

这是我的理解(我只是写了一句在函数的形式从概念上理解它)

的方法this.render() =功能(this.propsthis.state) 其中this.propsthis.state都是对象。

这意味着render()方法依赖于this.propsthis.state。无论何时,任何这些更改都会调用render()方法,并重新呈现该组件。

但是,如果我们希望手动调用render()方法,当某些数据在状态或道具对象内部深度变化而不改变对象本身时,我们可以通过调用forceUpdate()来实现。这里的render()方法在概念上成为调用forceUpdate()以及this.propsthis.state的方法的函数。

0

:?我浏览了链接页面,没有直接或以其他方式看到此声明。然而,声明仅仅意味着该方法读取道具和状态以便发出元素。

+1

此声明来自https://facebook.github.io/react/docs/tutorial.html –

+0

感谢您的链接。 – hazardous