form
form copied to clipboard
wrappedComponentRef is undefined in function component
class components with Form Wrraped could get this.form
but function components got undefined
`function InsertForm1 ({ form }) {
const formItemLayout = {
labelCol: { span: 24 },
wrapperCol: { span: 24},
};
const { getFieldDecorator } = form;
return (
class InsertForm extends Component{ render(){ const formItemLayout = { labelCol: { span: 24 }, wrapperCol: { span: 24}, }; const { getFieldDecorator } = this.props.form; return (
export default InsertFormWrapper1;`
having an issue here
I have created a demo app that uses wrappedCompenentRef prop in fully functional component and it works. Check it out https://codesandbox.io/s/wrappedcomponentref-upzhn . It would be helpful.
Just use use useImperativeHandle
// Your Function Form Component
function FunctionForm (props, ref) {
...
// set ref.current to form instance
React.useImperativeHandle(ref, () => props.form)
...
}
export default Form.create(React.forwardRef(FunctionForm))
When using it
// App.js
const formRef = React.useRef()
<FunctionForm wrappedComponentRef={formRef} />