score:0

Make sure you are listening to that store in your maps file if you are passing props to your component through maps file.

export const listenToStores = [CommonStore, store];
@connection(maps.listenToStores, maps.getStateFromStores)

score:0

Building on what Marina answered going from

var tempArray = imageArrayState
tempArray.push(5)
setImageArray(tempArray)

to

var tempArray = []
imageArrayState.foreach(value => {tempArray.push(value)})
tempArray.push(5)
setImageArray(tempArray)

made my app refresh

score:8

componentWillUpdate receives the incoming props as an argument. At this time, this.props is still the old props. Try changing your method like so:

void componentWillUpdate(nextProps, nextState) {
    L.geoJson(nextProps.data).addTo(this.map);
}

score:28

Because you're not changing the reference, so React's shallow compare doesn't detect the update.

I'm going to use a simple example with blog posts. In your reducer, you're probably doing something as follows:

case FETCH_NEW_POSTS
    let posts = state.posts;
    posts.push(action.payload.posts);
    return {
        ...state, 
        posts
    };

Instead of that, you must do something like the following:

case FETCH_NEW_POSTS
    let posts = [...state.posts]; // we're destructuring `state.posts` inside of array, essentially assigning the elements to a new array.
    posts.push(action.payload.posts);
    return {
        ...state, 
        posts
    };

Depending on your use case Object.assign() or lodash's clone/deepclone may be more idiomatic.

score:41

I had a similar problem and I found out the answer after read this:

Data gets set/updated/deleted in the store via the results of handling actions in reducers. Reducers receive the current state of a slice of your app, and expect to get new state back. One of the most common reasons that your components might not be re-rendering is that you're modifying the existing state in your reducer instead of returning a new copy of state with the necessary changes (check out the Troubleshooting section). When you mutate the existing state directly, Redux doesn't detect a difference in state and won't notify your components that the store has changed. So I'd definitely check out your reducers and make sure you're not mutating existing state. Hope that helps! (https://github.com/reactjs/redux/issues/585)

When I tried use Object.assign({}, object) as you, it didn't work anyway. So was when I found this:

Object.assign only makes shallow copies. (https://scotch.io/bar-talk/copying-objects-in-javascript)

Then I understood that I had to do this: JSON.parse(JSON.stringify(object))

or just this: {...object}

For Arrays: [...theArray]

I hope that this will help you


Related Query

More Query from same tag