所有
我是redux和react-redux的新手,我想知道我是否设计了todo项目组件(todolist的元素单元),如
const todo => ({id, todocontent}) {
return <li key={id}>{todocontent}</li>
}
然后我如何构建mapStateToProp函数并将其与connect?
一起使用说todo列表数据如下:
{
title: "TodoList",
version:"1.0",
todolist: [
{id:"id1", todocontent: "todo 1"},
{id:"id2", todocontent: "todo 2"}
]
}
答案 0 :(得分:0)
这样的事情:
class YourComponent extends Component {
render () {
return (
<div>
{this.props.items.forEach((item) => {
return <todo id={item.id} todocontent={item.todocontent} />
})}
</div>
)
}
}
const mapStateToProps = (state) => {
return {
items: state.<yourReducerName>.todolist
}
}
connect(mapStateToProps)(YourComponent)