Skip to content

React Router / Redux - Connected Component Not Passing Redux State to Props #989

@RaisinBread42

Description

@RaisinBread42

I am connecting a component to the redux store, but only the react-router props are passed. Not even setting a testVar in the mapStateToProps function works.

Code simplified:

//index.js
import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk' 
import {initialState} from './reducers/RootReducer';

const store = createStore(RootReducer,initialState, applyMiddleware(thunk));

ReactDOM.render((
    <Provider store={store}>
        <BrowserRouter>
            <App />
        </BrowserRouter>
    </Provider>
    ), document.getElementById('root'));

// App.js
import Home from './path/to/Home-component'
import About from './path/to/About-component'
...
<div>
<Switch>
      <Route exact path='/' component={Home}/>
      <Route path='/uploadsideletters' component={About}/>
      ...
    </Switch>
</div>
...

// About.js
...
const mapStateToProps = (state) => ({
    testVar: "test"
});

const mapDispatchToProps = (dispatch) => ({
   // empty for now
});

export default connect(mapStateToProps,mapDispatchToProps)(About);

When printing this.props in the render method to the console I get:
Object {history: Object, location: Object, params: Object, route: Object, routeParams: Object…}

My testVar is not there. Why is this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions