Complete the code to capture user input in a React Native TextInput.
const [name, setName] = useState(''); <TextInput value={name} onChangeText=[1] placeholder="Enter name" />
The onChangeText prop expects a function to update the state. setName updates the name state with user input.
Complete the code to handle form submission and log the captured data.
const handleSubmit = () => {
console.log('User name:', [1]);
};The name variable holds the current user input captured from the form.
Fix the error in the code to correctly update multiple form fields in state.
const [form, setForm] = useState({ email: '', password: '' });
const handleEmailChange = (text) => {
setForm({ ...form, [1]: text });
};To update the email field in the form state, use the key email in the object spread.
Fill both blanks to create a controlled TextInput for password with secure entry.
<TextInput value={form.[1] onChangeText={(text) => setForm({ ...form, [2]: text })} secureTextEntry={true} placeholder="Password" />The value and the key in setForm must both be password to keep the input controlled and update the correct field.
Fill all three blanks to create a form submission handler that prevents default, logs data, and resets form.
const handleSubmit = (event) => {
event.[1]();
console.log('Form data:', [2]);
setForm({ [3] });
};Calling preventDefault() stops the page reload. Logging form shows the data. Resetting form clears the fields.