我有一个带有以下树的应用程序:
src/
--/views
--validations.js
--/users
--UserCreate.js
我的validates.js代码:
import {
required,
minLength,
maxLength,
minValue,
maxValue,
number,
regex,
email,
choices
} from 'react-admin';
export const required = () => required("Campo obrigatório")
export const minLength = (value) => minLength(value,"Este campo deve ter o minimo de "+value+" caracteres")
export const maxLength = (value) => maxLength("Este campo deve ter o máximo de "+value+" caracteres")
export const email = () => email("Digite um e-mail válido")
export const passwordsMatch = (value, allValues) => value !== allValues.password ? 'As senhas não coincidem' : undefined;
我的UserCreate.js代码如下:
import React, { Component } from 'react';
import { Create, SimpleForm, TextInput, DisabledInput } from 'react-admin';
import { required, email, minLength,maxLength } from './../validations';
export const UserCreate = props => (
<Create {...props}>
<SimpleForm redirect="list">
<DisabledInput label="#" source="id" />
<TextInput source="name" validate={[required(),minLength(5),maxLength(20)]} label="Nome"/>
<TextInput source="email" validate={[required(),minLength(5),maxLength(20),email()]} label="E-mail"/>
<TextInput source="password" validate={[required(),minLength(8),maxLength(20)]} label="Senha" type="password"/>
<TextInput name="confirm_password" validate={[passwordsMatch]} label="Confirmar senha" type="password"/>
</SimpleForm>
</Create>
)
但是,在运行时出现以下错误:
./src/views/users/UserCreate.js
Attempted import error: 'email' is not exported from './../validations'.
我在做什么错了?
答案 0 :(得分:2)
您要导入email
并声明一个名为email
的常量。
这在您的代码中造成了冲突,并且从模块email
中提取了第一个react-admin
,该模块未导出。
您应该更改const的名称以使其起作用。