From ba758849e4aeec3459b7156c3cf78ac551fc5480 Mon Sep 17 00:00:00 2001 From: "De Silva, Dinuka" Date: Fri, 25 Aug 2017 19:07:18 +0530 Subject: [PATCH] gh-50: Moved the `todos` `init` method execution to `componentDidMount` This fixes #50 --- web/src/components/app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/src/components/app.js b/web/src/components/app.js index 20bd858..93f0267 100644 --- a/web/src/components/app.js +++ b/web/src/components/app.js @@ -16,7 +16,11 @@ export default class App extends React.Component { this.state = { todos }; - this.init(); + this.init = this.init.bind(this); + } + + componentDidMount() { + this.init(); } init() { @@ -24,6 +28,7 @@ export default class App extends React.Component { axios.get(BASE_URL + '/todos/getAll').then(function(response) { self.setState({todos: response.data.result.Items}); }).catch(function(error) { + self.setState({todos: [{}, {}]}); console.log(error); }); }