score:0

i spent lot of time to find out that when using more than 1 reducer (with combineReducers), then your mapStateToProps should point the correct reducer names, for example

const mapStateToProps = state => ({
  someVar: state.yourReducerName.someVar,
  loading: state.yourReducerName.loading,
  error: state.yourReducerName.error
});

score:2

What do your React components look like? Are you using internal state in them or props to push the data down. Usually I see the issue is with people setting the internal state of props with Redux state. You should be pushing props down to the components and they will re-render on update.

Also, check out https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en

to see if the props are really changing.

score:2

Create new copy of array from the prop state to re-render the component

render() {

const {allPost} = this.props;
//Use the spread operator to create a new copy of the array
const posts = [...allPost];

 const plansList = () => {
     return posts.length < 1 ? null : posts && <PlansList allPost={posts} 
   />;
 };

return (
  <>
    <Container className="mt-lg-5 pt-lg-5">
    {plansList()}
  </Container>
  </>
);
}

score:4

I use this solution to do it. I put the users on my state and update it on any change, with componentWillReceiveProps. Hope it helps :-)

class UserList extends React.Component {
    constructor(props) {
       super(props);
       console.log(this.props);
       this.state = {
          users: props.users
       };
    }
    componentWillReceiveProps(nextProps) {
        if (this.props.users !== nextProps.users) {
            this.setState({
                users: nextProps.users,
            });
        }
    }

  render() {
    const { users } = this.state;

    const userItems = users.map((user, idx) => {
        return(<li key={idx}>{user.username}</li>);
    });

    return (
      <div>
        <ul>
          { userItems }
        </ul>
      </div>
    );
  }
}

export default UserList;

score:5

Common problem in this case is using not reactive operations for changing state. For example use concat() for array, but not push() and so on.

score:21

I had a similar problem, just in case someone stumbles upon this, I needed to clone the array in order to re-render the view:

export const addFieldRow = () => (
    (dispatch: any, getState: any) => {
        const state = getState();
        const myArrayOfObjects = myArrayOfObjectsProp(state);
        const newObject = {
            key: "",
            value: "",
        };
        myArrayOfObjects.push(newObject);
        dispatch(addFieldRowAction({ myArrayOfObjects: [...myArrayOfObjects] })); <== here
    }
);

Related Query

More Query from same tag