最近研究react redux,在看redux官方实例的时候遇到了不懂得地方,希望得到大家的帮忙。
下面是redux中的实例
const App = () => (
<p>
<AddTodo />
<VisibleTodoList />
<Footer />
</p>
)
export default App
下面是react的实例
var CommentBox = React.createClass({
render: function() {
return (
<p className="commentBox">
<h1>Comments</h1>
<CommentList />
<CommentForm />
</p>
);
}
});
我想问的 两段代码都是components,下面的写法我能理解,就是不知道上面的写法的原理,或者说哪里有文档介绍这种写法
PHP中文网2017-04-11 11:04:52
Redux实例中,使用了react-redux库的connect和privder。
在实例containers路径中可以找到connect方法的使用,如下:
AppTodo = connect()(App)
具体可以看看react-redux/src/connect.js
connect方法,对函数进行了react component包装
PHP中文网2017-04-11 11:04:52
上下是一样的,上边的就是用了箭头函数而已。上边的是把三个组件放到一个p里,最后返回一个App组件,其实和下面的是一个意思。上面的相当于
function App(){
return (
<p>
<AddTodo />
<VisibleTodoList />
<Footer />
</p>
)
}
export default App
[箭头函数][1]