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?
Shahla, Sarah, Ameen, Nanoor and Muhammad diary
1 and 2- props get passed to the component-like function whereas the state is managed inside the component-like variable declared inside a function.
props can be passed from outside, whereas the state can only be defined and maintained inside the component itself.
Props are immutable but State is mutable.
3- the stateful components are keeping track of changing data, while stateless components print out what is given to them via props, or they always render the same thing.
4- we add them to the JSX, just like you would with HTML attributes. for example:
5-React will set up event listeners and handle events that happen inside the React app.,
Activate Lasers