我使用react-jsonschema-form来显示和验证表单,同时创建自定义验证中的自定义验证,该错误出现在" ..."句法。请找到以下代码
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"));
我在&#34; ...错误&#34;的行处得到错误。任何人都可以帮我解决这个问题。
答案 0 :(得分:1)
如果您要使用...
rest / spread运算符,则需要使用插件。这是babel插件:
https://babeljs.io/docs/plugins/transform-object-rest-spread/