Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React how to apply`componentDidMount()

I am using redux and reactjs. I need to add few function in componentDidMount() to the following root react component.

I am not using react class extend. How can I apply componentDidMount() and my logic there?

   const App = () => (
      <div>
        <NavigationContainer />
      </div>
    )

export default App
like image 374
Radex Avatar asked Dec 03 '25 21:12

Radex


1 Answers

You can wrap the JSX in a return call and simply do your logic before, even interacting with your redux store.

const App = () => {
  const willRunOnEachRender = 'runs on each render'
  return (<div>
    <NavigationContainer willRunOnEachRender={willRunOnEachRender} />
  </div>
 )
}
export default App
like image 54
Ken Stipek Avatar answered Dec 06 '25 10:12

Ken Stipek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!