Skip to content

Instantly share code, notes, and snippets.

@a-m-dev
Created July 1, 2018 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-m-dev/dc816782bbc5611bd131875a30f47669 to your computer and use it in GitHub Desktop.
Save a-m-dev/dc816782bbc5611bd131875a30f47669 to your computer and use it in GitHub Desktop.
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