Loading…

What is the difference between Stateless and Stateful Component?

In Stateless component we didn’t define state.State allows your component to change dynamically to the user input. In stateful component we define state for the component.This state is passing as props to other component.

Example

                                        

Stateless Component:

Import React from ‘react’;

 const ABC =() => {

   <div>

 <h1>Hello World</h1>

</div>

 

Stateful Component :

Import React,{Component} from ‘react’;

class ABC extends Component {

state={

    value: ‘’

}

handleChange(event) {

this.setState({

value: event.target.value

});

}

render(){

return(

 <input type=”text” value={this.state.value} onChange={this.handleChange} />

)

}}

Suggest An Answer

No suggestions avaliable!

Latest post from React js interview questions

Ask Question