You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some states derived from the URL and different navigate in different callbacks. For example:
const App = ({location}) => {
const { foo, bar } = parseUrl(location.pathname);
function onFooChange(newFoo) {
navigate(getUrl({ foo: newFoo, bar });
}
function onBarChange(newBar) {
navigate(getUrl({ foo, bar: newBar });
}
}
The issue is that if we invoke the onFooChange and then invoke onBarChange right away, the onBarChange is still using the OLD foo value which overwrites the new foo value.
// initially at /foo0/bar0onFooChange("foo1");// /foo1/bar0onBarChange("bar1");// /foo0/bar1. But the expected is /foo1/bar1
How should I work around this? Thanks!
some additional thoughts:
We wanted to use the URL as the source of truth. So we didn't want to create local states of foo and bar locally which might cause conflict between the states in URL and the local state.
Is there something like the setState callback so that I can leverage the previous state and add incremental changes to it instead of directly overwriting it?
Or I should use the promise returned by the navigate? Then I need to maintain a list of promises myself which I tend not to do.
The text was updated successfully, but these errors were encountered:
I have some states derived from the URL and different navigate in different callbacks. For example:
The issue is that if we invoke the
onFooChange
and then invokeonBarChange
right away, theonBarChange
is still using the OLDfoo
value which overwrites the newfoo
value.How should I work around this? Thanks!
some additional thoughts:
We wanted to use the URL as the source of truth. So we didn't want to create local states of
foo
andbar
locally which might cause conflict between the states in URL and the local state.Is there something like the
setState
callback so that I can leverage the previous state and add incremental changes to it instead of directly overwriting it?Or I should use the promise returned by the
navigate
? Then I need to maintain a list of promises myself which I tend not to do.The text was updated successfully, but these errors were encountered: