Skip to content

Instantly share code, notes, and snippets.

@gugl
Created September 30, 2015 00:41
Show Gist options
  • Save gugl/cc0cf2983de47def471b to your computer and use it in GitHub Desktop.
Save gugl/cc0cf2983de47def471b to your computer and use it in GitHub Desktop.
@TaskListBox = React.createClass
getInitialState: ->
taskLists: []
componentDidMount: ->
$.ajax
url: this.props.url
dataType: 'json'
cache: false
success: (data) =>
@setState
taskLists: data
error: (xhr, status, err) =>
console.error @props.url, status, err.toString()
handleTaskListSubmit: (taskList) ->
$.ajax
url: this.props.url
dataType: 'json'
type: 'POST'
data: {task_list: taskList}
cache: false
success: (data) =>
taskLists = this.state.taskLists.concat([data])
@setState {taskLists: taskLists}
error: (xhr, status, err) =>
console.error this.props.url, status, err.toString()
render: ->
`<div className="taskListBox">
Hello, world! I'm a Task List Box!
<TaskListForm onTaskListSubmit={this.handleTaskListSubmit}/>
<h1>Task Lists</h1>
<TaskListList taskLists={this.state.taskLists} />
</div>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment