Created
July 1, 2018 10:42
-
-
Save a-m-dev/dc816782bbc5611bd131875a30f47669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PropTypes } from 'react' | |
class CoursesPage extends React.Component { | |
constructor(props) { | |
super(); | |
this.state = { | |
course: { | |
title: '' | |
} | |
} | |
// Bindings | |
this.handleChange = this.handleChange.bind(this) | |
} | |
handleChange(e) { | |
// const course = this.state.course; | |
// course.title = e.target.value; | |
// this.setState({course: course}) | |
this.setState(Object.assign( | |
{}, | |
this.state, | |
{course: Object.assign({}, this.state.course, {title: e.target.value})} | |
)) | |
} | |
render() { | |
console.log(this.state.course); | |
return( | |
<div> | |
<h1>Courses</h1> | |
<h2>Add Course</h2> | |
<input | |
type='text' | |
onChange={this.handleChange} | |
value={this.state.course.title} /> | |
<input | |
type='submit' | |
value='Save' | |
onClick={this.handleSave} /> | |
</div> | |
) | |
} | |
} | |
export default CoursesPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment