react hooks + Ant Design
const [value, setValue] = useState('');//把vaule的值存起来,方便其他地方用;
const onChange = (value: any) => {
setValue(value.target.value)
}
<Input
value={value}
onChange={onChange}
/>
react hook
const inputRef = useRef<HTMLInputElement>(null);
<input type="text" ref={inputRef} />
<button onClick={() => { console.log(inputRef.current?.value) }}>输出</button>
- 用react的useRef属性声明一个inputRef
- 给input一个ref属性 把之前声明的inputRef给到它的ref。