szhsin / react-transition-state

Zero dependency React transition state machine
https://szhsin.github.io/react-transition-state/
MIT License
384 stars 13 forks source link

Why isMounted true by default when initialEntered: false and unmountOnExit: true? #655

Closed krutoo closed 1 month ago

krutoo commented 1 month ago

Hi, i use this library like this:

  // shown - is a prop of component

  const [state, toggle] = useTransition({
    timeout: 300,
    initialEntered: false,
    preEnter: true,
    unmountOnExit: true,
  });

  useEffect(() => {
    toggle(shown);
  }, [shown]);

fisrt render takes state:

{
  isEnter: false
  isMounted: true
  isResolved: true
  status: "exited"
}

How should I use hook to make isMounted false by default?

szhsin commented 1 month ago

The initialEntered is false by default, so you only need to set the mountOnEnter true for achieving isMounted false on the initial render.

const [state, toggle] = useTransition({
+   mountOnEnter: true,
    unmountOnExit: true,
});
krutoo commented 1 month ago

@szhsin Thanks a lot