Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forwardRef相关 #161

Open
ckinmind opened this issue Jun 30, 2020 · 0 comments
Open

forwardRef相关 #161

ckinmind opened this issue Jun 30, 2020 · 0 comments

Comments

@ckinmind
Copy link
Owner

ckinmind commented Jun 30, 2020

参考资料

问题产生

在antd中想要在上层函数式组件获取到下级组件中的一些方法

function Parent() {
 const childRef = useRef(null)
 return (
   <div>
     <Child ref=childRef />
   </div>
 )
}

// -------------------
function Child(props, ref) {
  const [form] = Form.useForm() // antd的form实例
  ref.current = form  // 这时候父组件就能通过childRef去调用子组件的form方法了
   return (
    ....
  )
}
export default React.forwardRef(Child)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant