Quantcast
Channel: How can I store and subscribe component state to redux store? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How can I store and subscribe component state to redux store?

$
0
0

I have a container "HomeIndexView" and component "Table"And I have both global and local component state of table.

Global table states are like below,

const initialState = {   allTables: [],   showForm: false,   fetching: true,   formErrors: null, }; 

and local component state of table is like below,

 componentWillMount() {   this.setInitialState();  } setInitialState() {  this.setState({ tableBusy: false }); }

When a user logs in, in HomeIndexView, it shows all tables from data base through fetching. So what I want to do is that connecting local component state to redux store so that when it changes state false to true, it changes background color of table. How should I connect local state to redux store? and should I create separate reducer and action for the local component's state?

Thanks in advance

--EDIT 1

import Table                from '../../components/tables/table';

I am importing LocalComponent (Table) to HomeIndexView to show. In my HomeIndexView, it renders all tables from database,

_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>   );  }

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images