2017-05-28 74 views
1

我正在玩弄有趣的方法來使表單剛剛建模json。隱形react-jsonschema-form

所以我讀過關於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")} /> 
     ); 
    } 
} 

然後我引用它在我創建反應的應用程序內的虛擬項目的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; 

但沒有任何呈現。 現在我卡住了,也許表單不能是嵌套的組件?可能嗎? 任何提示?

謝謝!

回答

3

React組件名稱必須以大寫字母開頭。嘗試將myForm重命名爲MyForm