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
Post a Comment