InterviewSolution
| 1. |
Give An Example Of Both Stateless And Stateful Components With Source Code? |
|
Answer» Stateless and Stateful components Stateless: When a component is “stateless”, it calculates STATE is calculated internally but it directly never mutates it. With the same inputs, it will always produce the same output. It means it has no knowledge of the past, current or future state changes. var React = require('react'); Stateful : When a component is “stateful”, it is a central point that STORES every INFORMATION in memory about the app/component’s state, do has the ABILITY to change it. It has knowledge of past, current and potential future state changes. Stateful component change the state, using this.setState method. var React = require('react'); Stateless and Stateful components Stateless: When a component is “stateless”, it calculates state is calculated internally but it directly never mutates it. With the same inputs, it will always produce the same output. It means it has no knowledge of the past, current or future state changes. var React = require('react'); Stateful : When a component is “stateful”, it is a central point that stores every information in memory about the app/component’s state, do has the ability to change it. It has knowledge of past, current and potential future state changes. Stateful component change the state, using this.setState method. var React = require('react'); |
|