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?
Sara Bakr, Aya Marmash, Wafa'a Al-hayek, Heyam M
1-Props are used to pass data from one component to another similar to function parameters whereas the state is managed within the component (similar to variables declared within a function), states is used to read and write data while props used only to read data
2-Props are used when you went to store data that can be accessed by the children of a React component .while state can only be used within a class component.
3-a stateful component is a component that holds some state. Stateless components, by contrast, have no state, Which means the stateful components keep track of changing data, while stateless components print out what is given to them via props, or they always render the same thing
4-adding them to the JSX
5-using event handlers, Event handlers determine what action is to be taken whenever an event is fired. This could be a button click or a change in a text input.
function Form() {
function handleSubmit(e) {
e.preventDefault();
console.log('You clicked submit.');
}
return (
Submit
);
}