Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Transitions from 1 -> 2 -> 1 #26

Open
juan-altatech opened this issue Apr 14, 2023 · 0 comments
Open

Fast Transitions from 1 -> 2 -> 1 #26

juan-altatech opened this issue Apr 14, 2023 · 0 comments

Comments

@juan-altatech
Copy link

juan-altatech commented Apr 14, 2023

If you have a transition like this:

const [phase, setPhase] = useState(1)
const transition = useSwitchTransition(phase, 300, 'out-in');

and you quickly cycle form 1 -> 2 -> 1:

setPhase(2);
setPhase(1);

the output of the stage in the transition callback will be 1, leave

{transition((state, stage) => (
/* stage will be equal to 'leave' */
...

Current workaround is to add a random number to phase:
export const setFormattedPhase = (phase) => {
return ${phase}_${Math.random()};
};

export const getFormattedPhase = (stage?: phase) => {
return Number(phase?.split('_')[0]);
};

then

const [phase, setPhase] = useState(1)
const transition = useSwitchTransition(setFormattedPhase(phase), 300, 'out-in');
...
setPhase(2);
setPhase(1);

To me it seems like a key issue, and transition-hook is just reusing a component that was not finished unmounting, but kept the stage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant