react hooks equivalent of componentdidmount code example
Example 1: alternative for componentdidmount
import React, { useEffect } from 'react'const SampleComponent = () => { useEffect(() => { // code to run on component mount }, [])return (<div>foo</div>)}export SampleComponent
Example 2: componentdidmount in hooks
useEffect(() => {
// Your code here
}, []);