3

Here is my App.js Code

import React from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import AOS from "aos";
import "aos/dist/aos.css";
import Home from "../Home/Home";
AOS.init();

function App() {
  return (
    <>
      <div className="App">
        <Router>
          <Route path="/">
            <Home />
          </Route>
        </Router>
      </div>
    </>
  );
}

export default App;

export default App;

Home.jsx

import React from "react";

export default function Home() {
  return (
    <>
      <div className="commitments">
        <p data-aos="fade-left">This is text fading</p>
      </div>
    </>
  );
}

I think this is the correct way, before using data-aos="fade-left" it working fine, But when I use data-aos the text got disappeared. I'm not getting what is the issue.

Nimra Haider
  • 119
  • 3
  • 11

1 Answers1

4

You should run AOS.init(); after your app mounts:

function App() {

  useEffect(() => {
    AOS.init();
  }, []);

  return (
    <>
      <div className="App">
        <Router>
          <Route path="/">
            <Home />
          </Route>
        </Router>
      </div>
    </>
  );
}

Since this library isn't designed for React, you will probably have to re-initialize this in future when your component re-renders. I recommend using an animation library built for React.

T J
  • 42,762
  • 13
  • 83
  • 138
  • Which animation library is built for React? As I want to animate text and images on scroll. – Nimra Haider May 02 '21 at 17:53
  • 2
    There's a lot of them: https://www.react-reveal.com/, https://www.npmjs.com/package/react-animate-on-scroll, https://github.com/gilbox/react-spark-scroll, https://github.com/react-component/scroll-anim do a search and pick one that best suits your needs – T J May 02 '21 at 17:57