./src/views/users/UserCreate.js尝试导入错误:'email'不会从'./../validations'导出

问题描述 投票:1回答:1

我有以下树的反应应用程序:

src/
--/views
  --validations.js
  --/users
    --UserCreate.js

我的validations.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'.

我究竟做错了什么?

reactjs react-admin
1个回答
2
投票

您正在导入email并声明一个名为email的常量。

这会在您的代码中产生冲突,并且它会从未导出的email模块中获取第一个react-admin

您应该更改const的名称以使其工作。

© www.soinside.com 2019 - 2024. All rights reserved.