DEV Community

Discussion on: React Interview Questions 🔥

Collapse
 
adamaslan profile image
Adam Aslan • Edited
class User extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      message: 'Welcome to React world'
    }
  }

Enter fullscreen mode Exit fullscreen mode

Also isnt talking about State like this ^ and with setstate no longer best practices?

Collapse
 
sobingt profile image
Sobin George Thomas • Edited

@adamaslan Well, you should not call setState() in the constructor(). Instead, if your component needs to use local state, assign the initial state to this.state directly in the constructor.
src: reactjs.org/docs/react-component.h...

React Screenshot

Some comments have been hidden by the post's author - find out more