Skip to content

Commit

Permalink
Make suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Aug 12, 2021
1 parent fe2de12 commit 9718d3c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/withOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 9718d3c

Please sign in to comment.