Im trying to write task manager with mLab database. Im using axios http client. The problem is that when I'm trying to add a new task the app do not re-render I have to manually refresh the page to make it work.
class App extends Component {
constructor() {
super()
this.state = {
tasks: []
}
}
addTask(text) {
axios.request({
method: 'post',
url: 'https://exampleAPIaddress',
data: {
text: text,
completed: false
}
}).then(response => {
let tasks = this.state.tasks;
tasks.push({
_id: response.data._id,
text: text,
completed: false
})
this.setState = ({
tasks: tasks
})
}).catch((error) => {
console.log(error)
})
}
render() {
return (
<AddTask onAddTask={this.addTask.bind(this)} />
);
}
}