React Base Fiddle (JSX)

Starting point for creating JSFiddles with React.

by papish19

HTML

<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="container">
    <!-- This element's contents will be replaced with your component. -->
</div>

Babel + JSX

class Container extends React.Component {
  render() {
  	// some default data u waana set, call any api
    const form = {
    	name: 'john doe',
    };
    
    return <div>
      <FormComp form={form} />
    </div>;
  }
}

class FormComp extends React.Component {
	constructor(props) {
  	super(props);
    
    this.state = {
    	name: this.props.form.name,
    }
    
    this.submit = this.submit.bind(this)
  }
  
  submit(e) {
    e.preventDefault();
    console.log(this.state);
  }
  
  render() {
    const handleChange = (e) =>
    	this.setState({name: e.target.value});

		return (
    	<div>
    	  <form onSubmit={this.submit}>
          <input 
            type="text" 
            value={this.state.name} 
            onChange={handleChange} 
          />
    	    <button type="submit">Submit</button>
    	  </form>
    	</div>
    );
  }
}

ReactDOM.render(
  <Container />,
  document.getElementById('container')
);