question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mapStateToProps not recalled on action

See original GitHub issue

Hi,

action:

import * as types from './constants.js';

export function changeLook(multipleOutFitLook) {
    return {
        type: types.CHANGE_LOOK,
        multipleOutFitLook
    };
}

reducer:


import * as types from '../actions/constants.js';
import assign from 'object-assign';

const initialState = {

    multipleOutFitLook: 1

};

export default function friends(state = initialState, action) {
    debugger;
    switch (action.type) {

        case types.CHANGE_LOOK:
            const newLookNumber = action.multipleOutFitLook;
            return assign({}, state, {multipleOutFitLook: 2})

        default:
            return state;
    }
}

app

export default class App extends Component {

    constructor(props) {
        super(props);
    }



    render() {
        let {productData, w3cDigitalDataJson, locale, language, dispatch} = this.props;
        const actions = bindActionCreators(appAction, dispatch);


                <h1 onClick={function() {
                console.log(actions.changeLook(2))
                }}>Hello - {this.props.look}</h1>

            </section>
        );
    }
}
function mapStateToProps(state) {
    return {
        look: state.default.multipleOutFitLook
    };
}

let connectApp = (typeof document !== "undefined" ? connect(mapStateToProps)(App) : App);

export default connectApp

In the app, i am trying to update multipleOutFitLook, when I click the h1, but the function mapStateToProps, is only called on the initial page load.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Sep 30, 2015

No problem, glad to help.

0reactions
thabticommented, Sep 30, 2015

@gaearon you are amazing, i am trying to get redux adopted by my team (net-a-porter.com/mrporter.com). Thank you so much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux connected React component not updating until a GET ...
My react app uses a redux connected component to render data from backend for a project page, so I called a GET dispatch...
Read more >
Connect | React Redux
Your mapStateToProps functions are expected to return an object. This object, normally referred to as stateProps , will be merged as props to ......
Read more >
Using state from your Store in your views - Human Redux
Recall from the action creators chapter that bindActionCreators() takes an object of action creator functions and returns an object with all the same...
Read more >
06 React Redux connect map state and dispatch - YouTube
This is a video tutorial series on React and Redux. This video covers using connecting components with the redux store using mapStateToProps ......
Read more >
Async Redux, Tools - Lecture 10 - CS50 Video Player
0:12:07And if you recall, action types are just that key · 0:12:10in an action that lets us ... 0:28:07And if not, then we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found