Closed giligiliduang closed 5 years ago
const Lorry = forwardRef((props, ref) => { const startLorry = () => { console.log('start') } const stopLorry = () => { console.log('stop') } useImperativeHandle( ref, () =>({ startLorry, stopLorry }) ) return ( <> ('') </> ) }) function main(){ let lorryRef=useRef(null) useEffect(()=>{ lorryRef.current.startLorry() //报错,因为lorryRef.current为null },[]) <Lorry ref={lorryRef}></Lorry> }
代码如上,这个问题在React里面是不存在的
已经修复
代码如上,这个问题在React里面是不存在的