Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+10 votes

Is there any way besides methods like componentDidmount? componentDidUpdate? componentWillMount? in react?

asked in CSC490_Spring202021 by (8 points)

2 Answers

+6 votes
Best answer

You can try useEffect in React Hook

answered by (8 points)
selected by
+3 votes

Yes, as stated below, useEffect is another equivalent and any function passed w/ useEffect is ran each time the component is rendered - unless you have a second argument being passed. If the second argument is an empty array it will behave like componentDidMount.

Also check this out: https://react-hooks-cheatsheet.com/useeffect

Sources: https://stackoverflow.com/questions/53945763/componentdidmount-equivalent-on-a-react-function-hooks-component#:~:text=There's no componentDidMount on functional,read the documentation on useEffect .

answered by (8 points)