Q.1 Can we share state between components ?
Answer: We can't send state between components. But props do. We can send props between components.
Q.2 Can we make SectionList with the help of custom map() or flat-list ?
Answer: Yes / But SectionList provide many extra usefull features by-default. So we should use SectionList.
Q.3 Why we use render() method /
Answer: In classes, when we need to return/print data/UI/View then we need that function to display.
Q.4 How we define state in class component ?
Answer: We need contructor method. It is a life-cycle method hook call/run automatically. In constructor we define keyword "this.state = {}". This is an object.
Note: Every ley in state object is a state.
constructor() {
this.state = {
name : 'Adnan' ,
country: 'Pakistan'
}
}
this.state came from parent class conponent. To use parent class we use the super() method in contsructor.
It also same in Java,Typescript.
Display state like so { this.state.name }
Comments
Post a Comment