Created
December 15, 2018 13:34
-
-
Save himanshu-dixit/af12c657788d85ad4c7f4119fb4d565d 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, { Component } from 'react'; | |
import {Mutation} from 'react-apollo'; | |
import {addTodo, getTodos} from '../../Queries'; | |
class AddTodos extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
task: "", | |
user: localStorage.getItem("user"), | |
completed: false | |
} | |
this.handleTask = this.handleTask.bind(this); | |
} | |
addtodo(insert_todos) { | |
insert_todos({ variables: this.state, refetchQueries: [{ query: getTodos }] }); | |
} | |
handleTask(event) { | |
this.setState({task: event.target.value}); | |
} | |
render() { | |
return ( | |
<Mutation mutation={addTodo}> | |
{(insert_todos) => ( | |
<div> | |
<input type="text" name="name" value={this.state.task} onChange={this.handleTask} | |
placeholder="Enter the task name"/> | |
<div className="add-task" onClick={() => this.addtodo(insert_todos)}>+</div> | |
</div> | |
)} | |
</Mutation> | |
); | |
} | |
} | |
export default AddTodos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment