Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Created April 18, 2019 05:24
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 the-teacher/02c4f629543b402ed735dffd46358b3b to your computer and use it in GitHub Desktop.
Save the-teacher/02c4f629543b402ed735dffd46358b3b to your computer and use it in GitHub Desktop.
class Task extends React.Component {
constructor(props) {
super(props)
this.state = {
taskIsDone: false
}
}
onCompletedHandler (data) {
this.taskIsDone()
}
taskIsDone () {
this.setState({ taskIsDone: true })
}
render() {
if (this.state.taskIsDone) {
return <TaskIsDone />
}
return (
<Query query={checkIfTaskIsDone} onCompleted={this.onCompletedHandler} >
{({ loading, error, data }) => {
if (loading) return <Loader>Loading...</Loader>
if (this.state.taskIsDone) {
return <TaskIsDone />
}
return (
<TaskIsNotDone
taskId={data.task.id}
taskIsDoneHandler={this.taskIsDone}
/>
)
}}
</Query>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment