Skip to main content

Posts

Showing posts with the label React Constructor Method

React Constructor Method | Components Lifecycle

The Constructor Method  - The  constructor()  method is called when the component is initiated (before anything else). Here we can set up the initial state and other initial values. The  constructor()  method is called with the props, as arguments and we should always start by calling the  super(props)  before initiated anything else. Explore to Understand   -  React Lifecycle Components As an Example, import   React   from   'react' ; class   Header   extends   React . Component  {    constructor ( props ) {      super ( props );      this . state  = { msg:   "welcome!" };   }    render () {      return  (       < h2 >{ this . state . msg } you anil</ h2 >     );   } } ...