Please discuss with your teams and answer these questions in your own words.
- What is the difference between state and props in React?
- When should you use state and props in React?
- What is the difference between stateful and stateless components in React?
- How can you pass props to a component in React?
- How does react handle events, can you write an example?
Team : Ali , Darya , Abdulbari , Dalia , Fadi
1-Props is used for transferring data between components, but state is used for changing state of a data (varible)
2-When you want to pass a data from parent component to child component then you have to use Props, and when you want to manage a state of a data then you have to use STATE for it.
3-Sateful component contains state and the data will be modified by time, but stateless, not hold any state more looks like static components
4-You will pass it as a parameter from parent component to the child components
5-we use html attributes, for example, unlike, onSumbit...
Code example :
" class LoggingButton extends React.Component {
handleClick() {
console.log('this is:', this);
}
render() {
// This syntax ensures
this
is bound within handleClickreturn (
<button onClick={() => this.handleClick()}>
Click me
);
}
} "