我在 React 组件中使用带有类型文件的受控输入。如果我在输入组件中选择了一个文件并切换主组件的显示/隐藏行为。在 Component re-renders 输入不起作用并抛出以下错误:
Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
const [filePath, setPath] = useState('');
<input
key={"a"}
id={"1"}
name={"file input"}
type="file"
value={filePath}
multiple
onChange={(event) =>
setPath(event.target.value)
}
/>