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