方案一:Umi3
export default connect((state) => {
return {
list: state.list,
}
}, null, null, { forwardRef: true })(C2)
// 老版本 4以下
export default connect((state) => {
return {
list: state.list,
}
}, null, null, { withRef: true })(C2)
方案二:Umi3以下
let Component = (props)=>{
const {refInstance} = props;
// 只要是实例都行useForm和useRef创建的都可以
const [form] = Form.useForm();
useImperativeHandle(refInstance,()=>({
submit:()=>{
form.submit();
}
}));
return (
<>xxx</>
)
};
Component = connect(xxx, xxx)(Component);
//注意:这里不要在Component上使用ref;换个属性名字比如refInstance;不然会导致覆盖
export default React.forwardRef( (props,ref) => <Component {...props} refInstance={ref} />);