Components
Components
**************************************************************
Separation
-
Every Component must return some markup (JSX) and separate JS File
**********************************************************
Import export
************************************************
Types of Components
No state,
No render method,
Resuable
simple,easy,
Better to use
hook used
********************************************************
************************************
State,-
built in react object in a class component
hold data and have state.
render method
We can extend
Reusable
******************************************************
Adv- we can extends or Reusable class Components
- Disadvantage
Complex,
Heavy and slow interaction
Consume more memory
complex in config.
***************************************
//IMP=>
We can derived or pass data through " props " to another Component.
works with Hooks-
******************************************
Immutable
***************************************
state-
We can Change and update state whenever we want i.e on events or actions
- Mutable
- we can change state
***************************************
this.state=({
})
this.setState({
})
*******************************
render method-
// render=
*************************************************************8
//super method-
// when we inherit parent component in any class then used super method
//i.e so 1st we need to call parent constructor to accessing parent methods and
properties in child or derived class component i.e need to call then=>
// The super keyword is used to call the constructor of
// its parent class to access the parent's properties and methods.
//i.e when we inherit parent component in any class
*****************************************
//automatically invoked
constructor()
{
super();
console.log('Constructor Called');
// ***************************************************************
</>
)
}
constructor()
{
super();
this.state({
name:'',
})
render()
{
return(
<>
</>
)
}
}
******************************************************
props eg
clickHere=()=>{
//Functional component
<button onClick={()=>ClickHere()}></button>
<button onClick={ClickHere}></button>
//class
<button onClick={this.ClickHere}></button>
<button onClick={()=>this.ClickHere()}></button>
//render method
<button onClick={clickhere}></button>
<button onClick={()=>Demo()}></button>
function clickHere()
{
}
this.state=({
stud1:true,
stud2:false,
stud3:false,
})
button onClick
{
this.state.stud1:
<div>
//student data
</div> :null
this.setState({
stud1()
{
this.setState({
stud1:!this.state.stud1
stud2:false
stud2:false
})
}
})
In React - One Way Binding- One directional Data flow - parent to child
in Angular- Two way binding