Skip to content

Commit

Permalink
Apply ref access fix to presence component
Browse files Browse the repository at this point in the history
  • Loading branch information
chungweileong94 committed Apr 27, 2024
1 parent 82bff21 commit 45b510a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/react/presence/src/Presence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const Presence: React.FC<PresenceProps> = (props) => {
: React.Children.only(children)
) as React.ReactElement;

const ref = useComposedRefs(presence.ref, (child as any).ref);
// Accessing the ref from props, else fallback to element.ref
// https://github.com/facebook/react/pull/28348
const childrenRef = child.props.ref ?? (child as any).ref;
const ref = useComposedRefs(presence.ref, childrenRef);
const forceMount = typeof children === 'function';
return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
};
Expand Down

0 comments on commit 45b510a

Please sign in to comment.