<div id="root" class="panel center"></div>
.body {
  	margin: 0;
  padding: 0;
  height: 100vh;
}

.app {
  padding: 10px;
}

.box {
  margin: 10px 0;
}
const { useEffect, useRef } = React;

function Box({ children }) {
  return <div className="box">{children}</div>;
}

function Container({ children }) {
  return <div><Box>Nested Box</Box></div>;
}

function App() {
  const el = useRef();
  const q = gsap.utils.selector(el);
  
  useEffect(() => {
    
    // Target any descendant with the class of .box - no matter how far down the descendant tree. Uses el.current.querySelectorAll() internally
    gsap.to(q(".box"), {
      x: 100,
      stagger: 0.33,
      repeat: -1,
      repeatDelay: 1,
      yoyo: true
    });
  }, []);
  
  return (
    <div className="app" ref={el}>
      <Box>Box</Box>
      <Container/>
      <Box>Box</Box>
    </div>
  );
}

ReactDOM.render(<App />, document.querySelector("#root"));
View Compiled
Run Pen

External CSS

  1. https://codepen.io/GreenSock/pen/gOWxmWG.css

External JavaScript

  1. https://unpkg.co/gsap@3/dist/gsap.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js
  3. https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js