javascript - How do I get access to my container/store in this top level file? -


i'm getting started react/redux , have everthing working fine redux when test it.

however, not able connect actual application.

i assume should use connect(), don't know how/where to.

// libraries import react 'react'; import reactdom 'react-dom';  // redux import { provider } 'react-redux'; import store './redux/store'; import './redux/test.js'; import {connect} 'react-redux'   class app extends react.component {    constructor(props, test) {     super(props);   }    render () {     return (       <div id = 'contents'>       </div>     )   } }  const app = document.getelementbyid('app'); reactdom.render(    <provider store={store}>     <app></app>   </provider>  , app); 

you need connect component app.

by example let's assume have value in reducer named reducer in store :

// libraries import react 'react'; import reactdom 'react-dom';  // redux import { provider } 'react-redux'; import store './redux/store'; import './redux/test.js'; import {connect} 'react-redux'   class app extends react.component {    constructor(props, test) {     super(props);   }    render () {     // can use data props     return (       <div id = 'contents'>         {this.props.data}       </div>     )   } }  const mapstatetoprops = (state, ownprops) => {   // bind store state component data   return {     date: state.reducer.value,   }; }  const mapdispatchtoprops = (dispatch) => {   // bind actions component }  const connectedapp = connect(mapstatetoprops, mapdispatchtoprops)(app);  const app = document.getelementbyid('app'); reactdom.render(    <provider store={store}>     <connectedapp></connectedapp >   </provider>  , app); 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -