Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action updates devtools store properly but doesn't re-render with the correct state #30

Closed
andre0799 opened this issue Nov 5, 2015 · 2 comments

Comments

@andre0799
Copy link

so on my component I call this dispatch(actions.createExercise(planId))

which calls this action creator

export function createExercise(id) {
  return dispatch => {
    console.log('createExercise')
    const exerciseId = uuid();

    dispatch({
        type: 'CREATE_EXERCISE',
        id: exerciseId,
        exercise: {
          title: 'CREATE_EXERCISE',
          id: exerciseId
        }
      });

    return function(){
      dispatch({
          type: 'ADD_EXERCISE_TO_PLAN',
          id,
          exerciseId
        });
    }
  };
} 

and this are the reducers (only pasted the relevant parts of the code)

const plans = (state = {}, action) => {
  switch (action.type) {
  case 'ADD_EXERCISE_TO_PLAN':
    console.log(action.type)
    return {
      ...state,
      [action.id]: {
        ...state[action.id],
        exercises: [
          ...state[action.id].exercises,
          ...action.exerciseId
        ]
      }
    };  

}


const exercises = (state = {}, action) =>  {
  switch (action.type) { 

  case 'CREATE_EXERCISE':
    return {
      ...state,
      [action.id]: {
        ...action.exercise
      }
    }; 

}

As you can see on the screenshot below the actions were properly called, but the state wasn't properly updated on the component. The printed state (which was printed on the render method) doesn't contain the updated state, neither the exercise was added to the entities object nor the exerciseId was added to the exercises array on the Plan object

image

but if you see on the dev tools, both objects are correct... Thanks in advance, any help is appreciated

image

image

@gaearon
Copy link
Collaborator

gaearon commented Nov 5, 2015

It's hard to say what the exact problem is because there are several deeper problems in your example app:

Please fix these two issues, update the project, and if you still have problems, I can take another look. In the future, please avoid asking questions as issues in Redux Thunk repo, as your questions are not related to it. It's best to ask for help on StackOverflow.

@gaearon gaearon closed this as completed Nov 5, 2015
@andre0799
Copy link
Author

The problem was only that I was not updating the component state when it received the new props... :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants