1

我有一个组件,其中有一个表单和validationSchema(我使用formik)。

我的验证模式使用 react-intl 来翻译消息。不幸的是,我在两个不同的地方有相同的模式,我想将它导出到另一个地方导入。由于国际,我不知道该怎么做。

我的代码:

import { injectIntl, intlShape } from 'react-intl';

const MyComponent = (props) => {

const { intl } = props;

const setValidationSchema = () => ({
  companyName: string(),
  firstName: string().required(),
  lastName: string().required(),
  dateOfBirth: date().required().typeError(intl.formatMessage(messages.dateOfBirth)),
  street: string().required(),
});

4

1 回答 1

1

You can use it like:

export const MyComponent =(props) =>( ) and pass the reference of intl as a parameter in the schema

I hope that helps you

于 2020-05-04T22:04:53.287 回答