【发布时间】:2016-05-27 17:24:48
【问题描述】:
通过定义 mapStateToProps 的 connect() 函数创建容器组件,可以访问整个树状态的状态 (store.getState())。
比如我已经合并了状态树:
{
loaded: true,
threads: [
{
id: 1,
title: "Thread 1",
messages: [
{
id: 1,
text: "Message 1"
}
]
},
{
id: 1,
title: "Thread 2",
messages: [
{
id: 2,
text: "Message 2"
},
{
id: 3,
text: "Message 3"
}
]
}
]
}
我应该如何访问给定线程的特定消息?
const mapStateToProps = (state) => {
return {
messages: getMessagesByThread(state.threads, <threadId>)
}
}
在这种情况下,假设我不想在存储状态树 (store.getState().activeThreadId) 中有“activeThreadId”参数。
提供 threadId 的最佳其他可能性是什么?
【问题讨论】:
标签: javascript reactjs redux flux