Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+10 votes

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

asked in CSC490_Spring202021 by (1 point)

2 Answers

+6 votes
 
Best answer

You can try useEffect in React Hook

answered by (1 point)
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 (1 point)
...