UNPKG

@fruits-chain/react-native-xiaoshu

Version:
38 lines (34 loc) 1.28 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import RCForm from 'rc-field-form'; import React, { useImperativeHandle, forwardRef } from 'react'; import { usePersistFn } from '../hooks'; import Toast from '../toast'; import useForm from './useForm'; /** * 默认处理错误的回调 */ const defaultOnFinishFailed = errorInfo => { Toast(errorInfo.errorFields[0].errors[0]); }; const InternalForm = (_ref, ref) => { let { onFinishFailed = defaultOnFinishFailed, form, onFinish, ...restProps } = _ref; const [wrapForm] = useForm(form); useImperativeHandle(ref, () => wrapForm); const onFinishPersistFn = usePersistFn(() => { onFinish(wrapForm.getFieldsValue(true)); }); return /*#__PURE__*/React.createElement(RCForm, _extends({}, restProps, { component: false, form: wrapForm, onFinishFailed: onFinishFailed, onFinish: onFinishPersistFn })); }; const Form = /*#__PURE__*/forwardRef(InternalForm); export default Form; //# sourceMappingURL=form.js.map