2

I am converting my project from angular to reactjs. But I got stuck at ng-init. I don't know what is the equivalent of ng-init in reactjs in react way. Please help me, anyone, with this.

kameshsr
  • 327
  • 3
  • 13
Djkrishna
  • 23
  • 1
  • 3

2 Answers2

2

If you're using class based components then its equivalent is ComponentWillMount() and if you're using function based component then it can be done in useEffect() hook provided by React.

ammadkh
  • 569
  • 3
  • 9
2

Use componentDidMount for class component

  componentDidMount() {
    ...
  }

The componentDidMount() method runs after the component output has been rendered to the DOM.

and use useeffect for the functional component

useEffect(() => {
 ...
});
Deepu Reghunath
  • 8,132
  • 2
  • 38
  • 47