0

I am using the following component:

export const Home =() =>
        <div className="cardBox" style={styleBox}>
            <CardTrail></CardTrail>
            <CardTrail></CardTrail>
            <CardTrail></CardTrail>
            <Footer></Footer>
          </div>

and I am was trying to make a get API request using AJAX. Cant find a suitable way to do it with functional components. I achieved it with class components via the help of componentDidMount() lifecycle method.

abcbc
  • 1
  • 1

1 Answers1

0

The equivalent in a functional component if using React 16.8 or higher is to use an effect with an empty dependency list:

React.useEffect(() => {
  // ajax call here
}, [])
Brian Thompson
  • 13,263
  • 4
  • 23
  • 43