我有一个容器“HomeIndexView”和组件“表” 而且我有全局和本地组件状态表。如何存储和订阅组件状态到Redux存储?
全局表的状态是像下面,
const initialState = {
allTables: [],
showForm: false,
fetching: true,
formErrors: null,
};
和局部表的组件的状态是像下面,
componentWillMount() {
this.setInitialState();
}
setInitialState() {
this.setState({ tableBusy: false });
}
当,在HomeIndexView用户登录,它示出了从数据的所有表通过获取基地。 所以我想要做的是将本地组件状态连接到redux store,以便当它将state false更改为true时,它会更改表的背景颜色。我应该如何将本地状态连接到Redux商店?我应该为本地组件的状态创建单独的缩减器和操作?
在此先感谢
--edit 1
import Table from '../../components/tables/table';
我进口LocalComponent(表),以HomeIndexView显现。 在我HomeIndexView,它呈现的所有表从数据库,
_renderAllTables() {
const { fetching } = this.props;
let content = false;
if(!fetching) {
content = (
<div className="tables-wrapper">
{::this._renderTables(this.props.tables.allTables)}
</div>
);
}
return (
<section>
<header className="view-header">
<h3>All Tables</h3>
</header>
{content}
</section>
);
}
_renderTables(tables) {
return tables.map((table) => {
return <Table
key={table.id}
dispatch={this.props.dispatch}
{...table} />;
});
}
render() {
return (
<div className="view-container tables index">
{::this._renderAllTables()}
</div>
);
}
你说的 '全球性' 的状态呢?你的意思是你创建了一个Redux商店,或者它只是你定义的'initialState'对象?如果是这样,那里。你能详细说明上述状态所在的组件层次结构吗? – Pineda
是的,我创建了一个Redux存储和'const initialState = {'是表组件的全局状态。组件层次结构是Authenticated container> HomeIndexView> Table Component –
对于本地组件,我创建是因为我希望数据库中的每个表都具有tableBusy的状态.. –