Skip to content

Commit

Permalink
Merge pull request #71 from DiamondLightSource/fix_deprecation_test_w…
Browse files Browse the repository at this point in the history
…arning

Fix findDOMNode deprecation warning in slideshow widget
  • Loading branch information
rjwills28 authored Dec 10, 2024
2 parents 20064d0 + f3d82a3 commit a25e906
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/ui/widgets/Slideshow/slideshow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ export const SwitchableWidget = (props: {
index: number;
children: [ReactElement];
transition: { readonly [key: string]: string };
nodeRef: React.Ref<HTMLDivElement>;
}): JSX.Element => {
// react-transition-group internally uses findDOMNode which
// is deprecated. Fix by passing nodeRef which points to the
// transitioning child.
return (
<SwitchTransition mode="out-in">
<CSSTransition
nodeRef={props.nodeRef}
classNames={props.transition}
key={props.index}
timeout={250}
Expand Down Expand Up @@ -69,6 +74,7 @@ export const SlideshowComponent = (
const [transition, setTransition] = useState(slideRightTransition);

log.debug(`Slideshow Index: ${childIndex}`);
const nodeRef = React.useRef<HTMLDivElement>(null);

return (
<div
Expand Down Expand Up @@ -104,6 +110,7 @@ export const SlideshowComponent = (
</button>
<div
ref={nodeRef}
style={{
position: "relative",
width: "80%",
Expand All @@ -114,7 +121,11 @@ export const SlideshowComponent = (
overflow: props.overflow ?? ""
}}
>
<SwitchableWidget index={childIndex} transition={transition}>
<SwitchableWidget
index={childIndex}
transition={transition}
nodeRef={nodeRef}
>
{props.children as [ReactElement]}
</SwitchableWidget>
</div>
Expand Down

0 comments on commit a25e906

Please sign in to comment.