301 Reading Four
React Forms
-What is a ‘Controlled Component’?
Answer- From the website https://reactjs.org/docs/forms.html
an input form element whose value is controlled by React
-Should we wait to store the users responses from the form into state when they submit the form OR should we update the state with their responses as soon as they enter them? Why.
Answer- We should store it as that state then becomes the “single source of truth”
-How do we target what the user is entering if we have an event handler on an input field?
Answer- The event runs on every keystroke and updates the React state so the value will update as the user types.
the Conditional (ternary) Operator Explained
- Why would we use a ternary operator?
Answer- because it is a single line boolean if statement.
- Rewrite the following statement using a ternary statement:
Answer x === y ? 'true" : 'false';