简体   繁体   English

reactjs应用程序中出现意外的令牌错误

[英]Unexpected token error in reactjs app

I'm using react-jsonschema-form to display and validiate form and while creating custom validation found in the Unexpected tocken error in the line which is having "..." syntax. 我正在使用react-jsonschema-form来显示和验证表单,并在具有“ ...”语法的行中的意外异常错误中创建自定义验证。 Please find the below code 请找到下面的代码

import React, { Component } from "react";
import { render } from "react-dom";

import Form from "react-jsonschema-form";

const SchemaForm = JSONSchemaForm.default;

let schema = {
 type: "string",
title: "FirstName",
minLength: 12,
required: true,
messages: {
required: "Please enter your First name",
minLength: "First name should be > 5 characters"
}
 };

  const MySchemaForm = props => {

  const transformErrors = errors => {
  return errors.map(error => {

  if (error.schema.messages && error.schema.messages[error.name]) {
    return {
      ...error,
      message: error.schema.messages[error.name]
    };
  }
  return error;
 });
 };

 return (
<SchemaForm
  { ...props }
  schema={schema}
  liveValidate
  showErrorList={false}
  transformErrors={transformErrors}
 / >
);
 };

class App extends React.Component {
 constructor(props) {
super(props);
this.state = {formData: {}};
 }
 onSubmit({formData}) {
this.setState({formData});
}
 render() {
  return (
  <div>
    <MySchemaForm formData=""/>
  </div>
);
}
}

React.render(<App />, 
         document.getElementById("app"));

Im getting the error at the line where "...error". 我在“ ...错误”的那一行得到错误。 Can anyone help me to resolve this issue. 谁能帮我解决这个问题。

You need to use a plugin if you're going to use the ... rest/spread operator. 如果要使用... rest / spread运算符,则需要使用插件。 Here's the babel plugin: 这是babel插件:

https://babeljs.io/docs/plugins/transform-object-rest-spread/ https://babeljs.io/docs/plugins/transform-object-rest-spread/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM