面试题答案
一键面试import React, { useState } from 'react';
const FormComponent = () => {
const [inputValue, setInputValue] = useState('');
const handleInputChange = (e) => {
const { value, name } = e.target;
setInputValue(value);
console.log(`值: ${value}, name属性: ${name}`);
};
return (
<form>
<input
type="text"
name="input1"
onChange={handleInputChange}
placeholder="输入框1"
/>
<input
type="text"
name="input2"
onChange={handleInputChange}
placeholder="输入框2"
/>
</form>
);
};
export default FormComponent;