Reputation: 546
For a simple component written like this:
import React from 'react'
const MyComponent = ({text}) => {
return(<div> {text} </div>
}
Is there a syntax for implementing lifecycle method like componentDidMount() or do I have to convert code to React.Component class?
Upvotes: 2
Views: 4129
Reputation: 947
In the alpha version of React there is an opt in feature called hooks which will address this. See more on hooks here https://reactjs.org/docs/hooks-overview.html
Upvotes: 0
Reputation: 816384
Is there a syntax for implementing lifecycle method like componentDidMount()
No.
do I have to convert code to React.Component class?
Yes.
See https://facebook.github.io/react/docs/state-and-lifecycle.html
Upvotes: 9