From 63ac70741545a8fd892634ad23254b89abdb404d Mon Sep 17 00:00:00 2001 From: orangemug Date: Fri, 17 Nov 2017 10:53:46 +0000 Subject: [PATCH] Call fetchSources after component mount. --- src/components/App.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index bb7d524..7ca7f2b 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -69,10 +69,10 @@ export default class App extends React.Component { this.layerWatcher = new LayerWatcher({ onVectorLayersChange: v => this.setState({ vectorLayers: v }) }) - this.fetchSources(); } componentDidMount() { + this.fetchSources(); Mousetrap.bind(['ctrl+z'], this.onUndo.bind(this)); Mousetrap.bind(['ctrl+y'], this.onRedo.bind(this)); } @@ -185,7 +185,7 @@ export default class App extends React.Component { } fetchSources() { - const sourceList = {...this.state.sources}; + const sourceList = {}; for(let [key, val] of Object.entries(this.state.mapStyle.sources)) { sourceList[key] = sourceList[key] || []; @@ -197,6 +197,7 @@ export default class App extends React.Component { return response.json(); }) .then((json) => { + // Create new objects before setState const sourceList = {...this.state.sources}; sourceList[key] = [];