handle resize on useTransition #1917
-
hi guys ! I'm working on a component with a full screen mode. So i have built this little transition to handle the switch between the component default and fullscreen mode. How can i handle resize using useTransition ? let containerRef = React.useRef<HTMLDivElement>(null)
let windowsDimensions = useWindowDimensions()
let boundingRect = containerRef.current?.getBoundingClientRect()
const transitions = useTransition(isFullScreen, {
from: {
top: boundingRect?.top ?? 0,
left: boundingRect?.left ?? 0,
width: boundingRect?.width ?? windowsDimensions.width,
height: boundingRect?.height ?? windowsDimensions.height,
zIndex: 10000,
},
enter: {
top: 0,
left: 0,
width: windowsDimensions.width,
height: windowsDimensions.height,
zIndex: 10000,
},
leave: {
top: boundingRect?.top ?? 0,
left: boundingRect?.left ?? 0,
width: boundingRect?.width ?? windowsDimensions?.width,
height: boundingRect?.height ?? windowsDimensions?.height,
zIndex: 10000,
},
})
return (<Relative
ref={containerRef}
style={{ minHeight: 400 }}
> {ReactDOM.createPortal(
transitions(
(styles, item) =>
item && (
<animated.div
style={{
...styles,
position: 'absolute',
}}
>
{...content goes here}
</animated.div>
)
),
document.body
)}
</Relative>) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Without seeing what you're trying to achieve (e.g. through a codesandbox) it's a bit hard to advise you well, are you able to share one? My initial thoughts are you're not getting the data you're expecting by trying to do something like access the ref in the render method or maybe theres an issue with ReactDOM.createPortal(
<div>
{transitions(
(styles, item) =>
item && (
<animated.div
style={{
...styles,
position: 'absolute',
}}
></animated.div>
)
)}
</div>,
document.body
) |
Beta Was this translation helpful? Give feedback.
Without seeing what you're trying to achieve (e.g. through a codesandbox) it's a bit hard to advise you well, are you able to share one?
My initial thoughts are you're not getting the data you're expecting by trying to do something like access the ref in the render method or maybe theres an issue with
Portal
where actually you need to use an arbitrary div to ensure something is always mounted (this is required if you use a library like Radix):