Created
April 18, 2019 05:24
-
-
Save the-teacher/02c4f629543b402ed735dffd46358b3b 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
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