redux: Component won't re-render (universal)

I have an action posting to my database, with the reducer successfully posting the response to my state. This works fine, however my component isn’t re-rendering automatically, I can only use the updated component with a manual re-render.

Here’s my component:

export default class Colours extends React.Component {

  componentDidMount() {
    this.props.getColours();
  }

  render() {...}

  addItem = () => {
    this.props.postColour({ 
      colour: 'pink' 
    });
  }

}

my action:

import req from 'axios';

export function postColour(value) {
  return {
    type: 'POST_COLOUR',
    promise: req.post('/api/colours', value)
  };
}

and my reducer:

import Immutable from 'immutable';

export default function colourReducer(state = new Immutable.Map(), action) {
  switch(action.type) {

    case 'POST_COLOUR': {
      return state.merge(action.res.data.colours)
    }

    ...
  }
}

Am I missing/doing something completely wrong for my props not to be updated as soon as the response is merged with my initial state?

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 23 (15 by maintainers)

Most upvoted comments

I honestly have no idea, i’m on OSX too.

You’re right I didn’t even notice that, that shouldn’t work at all…

I’ve just updated my io.js to 3.1.0 and now I’m getting your error haha… would you be able to leave this open and i’ll let you know when i’ve fixed it?

It’s working! What should I do to repro?