Next.js Discord

Discord Forum

Redux Syncronisity Issue

Unanswered
Netherland Dwarf posted this in #help-forum
Open in Discord
Netherland DwarfOP
Hey there, I recently upgraded my Next project from v10 -> 13. This also had me upgrade my node version/react version/ redux version, etc...
I have a class component that has the following included:
const mapDispatchToProps = dispatch => ({
    setOrder: order => dispatch(setOrder(order)),
    //...
});
const mapStateToProps = (store) => ({
    order: store.order,
    //...
});

//....

updateItemProp = (item) => {
    this.props.setOrder(item);
    aFunc(this.props.order, this.props);
};

When calling aFunc, prior to doing the update, the updated version of the order was being used
Now after the update, it's no longer using the updated version
Anyone have an idea as to a) why it was previously working b) how to get this to work now
Note: I can't use componentDidUpdate since it causes some other issues on the project (although it shouldn't, it's a legacy portion of the project)

1 Reply

Netherland DwarfOP
    // Use a setTimeout to push the function call to the end of the call stack
    setTimeout(() => aFunc(this.props.order, this.props), 0);

Adding this setTimeout worked for me