Replies: 1 comment
-
OK, I think i have some idea now, thanks to this and this (this second one is by Kent C. Dodds) I still cannot claim to understand this fully, will take me a couple more reads + use cases, but I know the anti-pattern now And based on this undestanding, the following works flawlessly import * as React from 'react';
import { Transition } from '@headlessui/react';
const MyTransition = ({ showTransition }: { showTransition: boolean }) => (
<Transition
show={showTransition}
enter="transition-opacity duration-700"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-opacity duration-700"
leaveFrom="opacity-100"
leaveTo="opacity-0"
// appear
>
<div className="p-8 mx-auto max-w-screen-xl bg-red-400">Hello</div>
</Transition>
);
export default function TestScreen() {
const [show, setShow] = React.useState(false);
return (
<div>
<button className="text-white" onClick={() => setShow(prev => !prev)}>
Toggle!
</button>
<MyTransition showTransition={show} />
</div>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to understand the difference between rendering the Transition component directly, or defining it as a separate component. And then calling it as a render function.
CASE I : Take this simple code. This works as intended.
CASE II : Lets define the transition as a separate component.
Now the transition does not work. It does do the visible/disappear bit, but without any transition.
Also, if you set
appear={true}
, the entry transition works, but the exit transition does notSo I can infer that it has something to do with rendering vs just defining the transition, but would love to hear a more informed explanation.
CASE III : And as the final case, lets do it this way. This now works again.
Beta Was this translation helpful? Give feedback.
All reactions