隐形反应-jsonschema-form

时间:2017-05-28 14:30:34

标签: forms reactjs

我正在玩有趣的方法来制作json模型。

所以我读过react-jsonschema-form

所以,我创建了一个自定义组件,它会呈现如下形式:

import React, { Component } from "react";   
import Form from "react-jsonschema-form";

const schema = {
  title: "Todo",
  type: "object",
  required: ["title"],
  properties: {
    title: {type: "string", title: "Title", default: "A new task"},
    done: {type: "boolean", title: "Done?", default: false}
  }
};

const log = (type) => console.log.bind(console, type);

export default class myFrom extends Component { 
    render(){
          return ( 
           <Form schema={schema}
            onChange={log("changed")}
            onSubmit={log("submitted")}
            onError={log("errors")} /> 
        ); 
    } 
}

然后我在我的create-react-app虚拟项目的app.js中引用了它:

import myFrom from './custom-forms-test'
class App extends Component {

  render() {
    return ( 
      <div className="App"> 
            <div className="App-header">
              <img src={logo} className="App-logo" alt="logo" />
              <h2>Welcome to React</h2>
            </div> 
                <myFrom/>
       </div> 
    );
  }
}

export default App;

但没有渲染。 现在我卡住了,也许表格不能成为嵌套组件?可能吗? 任何提示?

谢谢!

1 个答案:

答案 0 :(得分:3)

React组件名称必须以大写字母开头。尝试将myForm重命名为MyForm