Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Transition-Group: findDOMNode is deprecated in StrictMode

I am using the animation library react-transition-group in react for animating a TODO list using <TransitionGroup> and <CSSTransition> as shown below

<ul>
   <TransitionGroup className="todo-list">
      {incompleteTodos.map((task) => (
      <CSSTransition key={task.id} timeout={500} classNames={styles}>
         <li key={task.id}>
            <TodoTask
               todo={task}
               onClick={(todo) =>
            toggleTodo({ data: todo })}
            />
         </li>
      </CSSTransition>
      ))}
   </TransitionGroup>
</ul>

But I am getting the error in the console as below:

enter image description here

I read about using nodeRef={nodeRef} on the CSSTransition element mentioned in this official changelog and git issue as shown below but then it started behaving weird i.e. some of the elements are not appearing properly in UI as shown in the screenshot below code snippets:

const nodeRef = React.useRef(null)

and

<ul>
   <TransitionGroup className="todo-list">
      {incompleteTodos.map((task) => (
      <CSSTransition
         key={task.id}
         timeout={500}
         classNames={styles}
         nodeRef={nodeRef}
         >
         <li key={task.id} ref={nodeRef}>
            <TodoTask
               todo={task}
               onClick={(todo) =>
            toggleTodo({ data: todo })}
            />
         </li>
      </CSSTransition>
      ))}
   </TransitionGroup>
</ul>

This screenshot is taken after applying nodeRef in CSSTransition enter image description here

like image 641
Varun Sukheja Avatar asked Feb 02 '26 09:02

Varun Sukheja


1 Answers

You need to make a separate ref for each of the CSSTransitions. The easiest way to do that is to make a custom component:

<ul>
   <TransitionGroup className="todo-list">
      {incompleteTodos.map((task) =>
        <TransitionTodo key={task.id} todo={task}/>}
  </TransitionGroup>
</ul>
function TransitionTodo({todo}) {
  nodeRef = useRef();
  return (
    <CSSTransition
       timeout={500}
       classNames={styles}
       nodeRef={nodeRef}
     >
       <li ref={nodeRef}>
          <TodoTask
             todo={todo}
             onClick={(todo) =>
               toggleTodo({ data: todo })}
          />
       </li>
    </CSSTransition>
  );
}
like image 137
edemaine Avatar answered Feb 03 '26 23:02

edemaine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!