Skip to content

React 19 has removed the ReactDOM.findDOMNode method. #918

Open

Description

@MattCraftsCode

What would you like improved?

React 19 has removed the ReactDOM.findDOMNode method.

Please update and refactor performEnter method.

https://18.react.dev/reference/react-dom/findDOMNode

Activity

  1. mogzol commented on Jan 24, 2025

    @mogzol

    This can be worked around by ensuring you pass a nodeRef to all of the transitions:

    function MyComponent() {
      const nodeRef = React.useRef(null);
      return (
        <CSSTransition nodeRef={nodeRef} {...otherProps}>
          <div ref={nodeRef}>...</div>
        </CSSTransition>
      );
    }
  2. sergioviniciuss commented on Feb 5, 2025

    @sergioviniciuss

    @mogzol this bypasses the error, but also cuts the effect of the library... Is it still working normally for you?

    In my case I use it for slidedown transitions, and I also added this fix you shared, but although error is gone, the transition effect is gone.

  3. mogzol commented on Feb 5, 2025

    @mogzol

    @sergioviniciuss yes it still works exactly how it did before. Make sure that the ref is set to the correct element, if you inspect the value, nodeRef.current should be the element that you want the classes applied to.

  4. SBOpalG commented on Feb 5, 2025

    @SBOpalG

    I have found that the above work around is functional when the top level element is an html element but not if it's a React component.

    An example one that does not work:

    function MyComponent() {
      return (
        <div>...</div>
      );
    }
    
    function AnimateMyComponent() {
      const nodeRef = React.useRef(null);
      return (
        <CSSTransition nodeRef={nodeRef} {...otherProps}>
          <MyComponent ref={nodeRef} />
        </CSSTransition>
      );
    };

    This is fixed by adding the ref instead to the top level element that is an html element:

    function MyComponent({ passDownRef }) {
      return (
        <div ref={passDownRef}>...</div>
      );
    };
    
    function AnimateMyComponent() {
      const nodeRef = React.useRef(null);
      return (
        <CSSTransition nodeRef={nodeRef} {...otherProps}>
          <MyComponent passDownRef={nodeRef} />
        </CSSTransition>
      );
    };

    Passing this reference around may not be what you want to do, especially if you have an animate wrapper component like my codebase does. The solution I was able to find with my colleague was to use a context:

    // AnimateMyComponent.jsx
    import { Children, useRef, createContext } from "react";
    import { CSSTransition } from "react-transition-group";
    
    function AnimateMyComponent({ children }) {
      const component = Children.only(children);
      const nodeRef = useRef(null);
      return (
        <CSSTransition nodeRef={nodeRef} {...otherProps}>
          <AnimationContext.Provider value={nodeRef}>
            {component}
          </AnimationContext.Provider>
        </CSSTransition>
      );
    };
    
    export default AnimateMyComponent;
    
    export const AnimationContext = createContext(null);
    
    // MyComponent.jsx
    import AnimateMyComponent from "./AnimateMyComponent";
    import MyFunctionalComponent from "./MyFunctionalComponent";
    import MyClassComponent from "./MyClassComponent";
    
    function MyComponent({ myBoolean }) {
      return (
        <div>
          <AnimateMyComponent>
            {myBoolean ? (
              <MyFunctionalComponent />
            ) : (
              <MyClassComponent />
            )}
          </AnimateMyComponent>
        </div>
      );
    };
    
    export default MyComponent;
    
    // MyFunctionalComponent.jsx
    import { useContext } from "react";
    import { AnimationContext } from "./AnimateMyComponent";
    
    function MyFunctionalComponent() {
      const animationRef = useContext(AnimationContext);
      return (
        <div ref={animationRef}>...</div>
      );
    };
    
    export default MyFunctionalComponent;
    
    // what type AnimationContext would be in a typescript .tsx functional component
    const animationRef = useContext(AnimationContext as React.Context<React.RefObject<HTMLElement>>);
    
    // MyClassComponent.jsx
    import { AnimationContext } from "./AnimateMyComponent";
    
    export default class MyClassComponent extends React.Component {
      render () {
        return (
          <AnimationContext.Consumer>
            {(animationRef) => (
              <div ref={animationRef}>...</div>
            )}
          </AnimationContext.Consumer>
        );
      }
    };

    I hope this is helpful to all and also to you specifically, @sergioviniciuss :D

  5. mogzol commented on Feb 6, 2025

    @mogzol

    Another option is to create a wrapper component that handles creating and passing nodeRef internally. The only issue with this is that it will wrap all of your transitions in a <div> (or whatever HTML element you use here). This could break styling or other things if your code isn't expecting these elements to be wrapped.

    import React from "react";
    import CSSTransition, { CSSTransitionProps } from "react-transition-group/CSSTransition";
    
    export function CSSTransitionWrapped(props: React.PropsWithChildren<CSSTransitionProps>) {
      const nodeRef = React.useRef<HTMLElement>(null);
      const { children, ...propsRest } = props;
    
      function setRef(value: HTMLDivElement | null) {
        // Set the nodeRef to the first child of the div, emulating findDOMNode behavior
        nodeRef.current = value?.firstElementChild as HTMLElement;
      }
    
      return (
        <CSSTransition nodeRef={nodeRef} {...propsRest}>
          <div ref={setRef}>{children}</div>
        </CSSTransition>
      );
    }

    Then use it exactly like CSSTransition was used before, it will work with HTML children or react component children:

    Here the <div> will get transition classes applied to it:

    <CSSTransitionWrapped {...transitionProps}>
      <div>...</div>
    </CSSTransitionWrapped>

    And here the root element of SomeComponent will get the transition classes applied to it:

    <CSSTransitionWrapped {...transitionProps}>
      <SomeComponent />
    </CSSTransitionWrapped>
  6. todor-a commented on Feb 6, 2025

    @todor-a

    Stumbled upon this. Looks like a modern alternative.

  7. nikitayutanov commented on Feb 12, 2025

    @nikitayutanov

    Here's the improved version of the above solution by @mogzol, without the need for an additional div wrapper.

    Drawbacks:

    • Custom components should accept and pass ref as a prop to their container element.
    • If ref is already specified on children, it will be overridden.
    import { cloneElement, ReactElement, useRef } from 'react';
    import { CSSTransition } from 'react-transition-group';
    import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
    
    type Props = CSSTransitionProps & {
      // intended behavior: https://github.com/facebook/react/issues/31824
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      children: ReactElement<any>;
    };
    
    function CSSTransitionWithRef({ children, ...restProps }: Props) {
      const ref = useRef<HTMLElement>(null);
    
      const setRef = (value: HTMLElement | null) => {
        ref.current = value;
      };
    
      return (
        <CSSTransition nodeRef={ref} {...restProps}>
          {cloneElement(children, { ref: setRef })}
        </CSSTransition>
      );
    }
    
    export { CSSTransitionWithRef };
  8. TNAJanssen commented on Jul 4, 2025

    @TNAJanssen
  9. mattrunyon commented on Sep 15, 2025

    @mattrunyon

    Another option is to create a wrapper component that handles creating and passing nodeRef internally. The only issue with this is that it will wrap all of your transitions in a <div> (or whatever HTML element you use here). This could break styling or other things if your code isn't expecting these elements to be wrapped.

    import React from "react";
    import CSSTransition, { CSSTransitionProps } from "react-transition-group/CSSTransition";

    export function CSSTransitionWrapped(props: React.PropsWithChildren) {
    const nodeRef = React.useRef(null);
    const { children, ...propsRest } = props;

    function setRef(value: HTMLDivElement | null) {
    // Set the nodeRef to the first child of the div, emulating findDOMNode behavior
    nodeRef.current = value?.firstElementChild as HTMLElement;
    }

    return (
    <CSSTransition nodeRef={nodeRef} {...propsRest}>

    {children}


    );
    }
    Then use it exactly like CSSTransition was used before, it will work with HTML children or react component children:

    Here the <div> will get transition classes applied to it:

    <CSSTransitionWrapped {...transitionProps}>

    ...
    And here the root element of `SomeComponent` will get the transition classes applied to it:

    <CSSTransitionWrapped {...transitionProps}>

    This works without unintended styling issues if you add style={{ display: 'contents' }} to the wrapping div. It will basically make the div not exist for the purposes of layout, but still works to mimic the findDOMNode behavior

  10. welkup commented on Oct 13, 2025

    @welkup

    Thanks @mogzol!

    Props passed to the CSSTransitionWrapper meant to be pass-through were ending up on the wrapper div. To get them to be forwarded to the wrapped component instead:

        <CSSTransition nodeRef={nodeRef} {...propsRest}>
          {(status, childProps) => (
            <div ref={setRef}>
              {cloneElement(Children.only(children), childProps)}
            </div>
          )}
        </CSSTransition>
    

    Also, be careful if you are wrapping a component that renders using createPortal. findDOMNode handled this case, but the setRef function does not.

  11. infinitybuddha29 commented on Oct 7, 2026

    @infinitybuddha29

    if adding nodeRef everywhere isn't an option (or the CSSTransition sits inside some other lib you can't edit), I made a small build plugin that puts findDOMNode back for react-dom 19: https://github.com/infinitybuddha29/react-legacy-compat

    works with vite, webpack 5 and next 15/16, turbopack included. for next it's just

    // next.config.mjs
    import { withReactLegacyCompat } from "react-legacy-compat/next";
    export default withReactLegacyCompat({});

    nothing in node_modules gets patched. tested CSSTransition without nodeRef in dev and prod builds. it reads react internals (_reactInternals) under the hood, so treat it as a stopgap until libs move to refs

  12. fitzyracing1 commented on Oct 8, 2026

    @fitzyracing1

    If adding nodeRef everywhere isn't practical (or the transition sits inside a library like react-bootstrap 1.x or Material-UI 4): I published a fork, @fitzyracing/react-transition-group@4.4.6, that works on React 19 without nodeRef. It puts its own ref on the child, combined with any ref the child already has, and reads the node from that. On React 16.6–18 it still calls findDOMNode exactly like 4.4.5. Same API and callback arguments.
    To fix it inside your dependencies without changing code:

    "overrides": { "react-transition-group": "npm:@fitzyracing/react-transition-group@^4.4.6" }

    One caveat on React 19: the child has to accept a ref (a DOM element, a forwardRef component, or a function component that passes ref on). Otherwise pass nodeRef as before. Source and tests: https://github.com/fitzyracing1/react-transition-group. Happy to drop it if upstream ships a release.

  13. mrkevbro commented on Nov 28, 2026

    @mrkevbro

    If adding nodeRef isn't an option, for example because the transition is inside a library like react-bootstrap 1.x, reactstrap or react-bootstrap-table-next: I published an unofficial fork, @nerdnog/react-transition-group 4.5.0. It's 4.4.5 with the findDOMNode calls replaced, and nothing else changed.

    • On React 19 it finds the same element 4.4.5 did, by reading React's internal records. Children that don't pass a ref through, and render-prop children, still animate. On React 16 to 18 it still calls findDOMNode.
    • If it can't find the element, it warns in development and finishes the transition instead of crashing.
    • It needs no build step. Swap it in with one line in package.json:
    "overrides": { "react-transition-group": "npm:@nerdnog/react-transition-group@^4.5.0" }

    Yarn uses resolutions and pnpm uses pnpm.overrides. The readme covers apps that depend on react-transition-group directly.

    Tested on React 19.3.1, in dev and production builds, with react-bootstrap-table-next's expandRow, reactstrap's Carousel, and react-bootstrap 1.6's Collapse and Fade. react-bootstrap 1.6's Modal still crashes on React 19 for a separate reason: React 19 ignores its defaultProps.

    React doesn't support reading its internal records, so CI runs weekly against React's canary to catch breakage early.

    Code and issues: https://github.com/nerdnog/react-transition-group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions