What is Amazon Nova Act AI?

In React, a controlled component is an input element (like <input>
, <textarea>
, <select>
, etc.) whose value is controlled by the component’s state. Instead of letting the input element manage its own state, the parent component is responsible for updating the input’s value whenever the user types something. This makes the input’s behavior predictable and fully controlled by React.
Example of Controlled Component
import React, { useState } from 'react';
function ControlledInput() {
const [value, setValue] = useState(''); // State to hold the input's value
const handleChange = (event) => {
setValue(event.target.value); /
};
return (
<div>
<label>
Enter text:
<input type="text" value={value} onChange={handleChange} />
</label>
<p>Current value: {value}</p>
</div>
);
}
export default ControlledInput;
value
in the example) holds the current value of the input.value
Prop: The value
prop of the <input>
is set to value
from the component's state, making React control its value.onChange
event handler updates the component’s state with setValue
, so every keystroke triggers a state update.
Comments
Post a Comment