Answers
- Props are special objects that you use to pass the values/objects/functions from the parent component to a child component, whereas state belongs to a component – it could be global or local to the component. From a functional component perspective, you use the
useStatehook for local state anduseContextfor global state. - In general, events are objects generated by the browser on input such as
keydownoronclick. React usesSyntheticEventto ensure that the browser’s native events work identically across all browsers.SyntheticEventwraps on top of the native event. You used theonChange={(e) => setUserName(e.target.value)}code in the login component. Here,eisSyntheticEventandtargetis one of its attributes. TheonChangeevent is bound in JSX that callssetUserNamewhen the input value is changed. You can also use the same JavaScript technique to bind events such aswindow.addEventListener("click", handleClick).
Ideally, you...