Javascript 将useRef与旧版本的react组件一起使用?
如何对使用旧ref回调api的组件使用useRefJavascript 将useRef与旧版本的react组件一起使用?,javascript,reactjs,Javascript,Reactjs,如何对使用旧ref回调api的组件使用useRef const App = () => ( //how to get ref of input? <div> <Input ref={r => console.log(r)} /> <Button type="primary">Hello</Button> </div> ); const-App=()=>( //如何获取输入的ref? consol
const App = () => (
//how to get ref of input?
<div>
<Input ref={r => console.log(r)} />
<Button type="primary">Hello</Button>
</div>
);
const-App=()=>(
//如何获取输入的ref?
console.log(r)}/>
你好
);
也许这行得通
const App = () => {
const myRef = useRef(null);
return (
<div>
<Input
ref={r => {
myRef.current = r;
}}
/>
<Button type="primary">Hello</Button>
</div>
);
};
const-App=()=>{
const myRef=useRef(null);
返回(
{
myRef.current=r;
}}
/>
你好
);
};
你不能有一个useRef
???这是一个功能组件
const App = () => {
const inputRef = useRef(null);
// console.log(inputRef.current) // => <Input />
return (
<div>
<Input ref={inputRef} />
<Button type="primary">Hello</Button>
</div>
);
};
const-App=()=>{
const inputRef=useRef(null);
//console.log(inputRef.current)/=>
返回(
你好
);
};