diff --git a/lib/withOnyx.js b/lib/withOnyx.js index 40054021..834e1ad9 100644 --- a/lib/withOnyx.js +++ b/lib/withOnyx.js @@ -87,16 +87,20 @@ export default function (mapOnyxToState) { * @param {*} val */ setInitialState(statePropertyName, val) { + if (!this.state.loading) { + console.error('withOnyx.setInitialState() called after loading: false'); + return; + } + this.tempState[statePropertyName] = val; // All state keys should exist and at least have a value of null - if (!_.every(requiredKeysForInit, key => !_.isUndefined(this.tempState[key]))) { + if (_.some(requiredKeysForInit, key => _.isUndefined(this.tempState[key]))) { return; } - this.setState({...this.tempState, loading: false}, () => { - this.tempState = {}; - }); + this.setState({...this.tempState, loading: false}); + delete this.tempState; } /**