Skip to content

Commit

Permalink
Merge pull request #480 from bernhardoj/fix/falsey-value-is-ignored
Browse files Browse the repository at this point in the history
Re: Use initialValue when cached value is undefined
  • Loading branch information
yuwenmemon authored Feb 28, 2024
2 parents 1e7844c + e44fd24 commit 950e257
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/withOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function (mapOnyxToState, shouldDelayUpdates = false) {
(resultObj, mapping, propertyName) => {
const key = Str.result(mapping.key, props);
let value = Onyx.tryGetCachedValue(key, mapping);
if (!value && mapping.initialValue) {
if (value === undefined) {
value = mapping.initialValue;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/withOnyxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ describe('withOnyxTest', () => {
key: ONYX_KEYS.SIMPLE_KEY,
initialValue: 'initialValue',
},
simple2: {
key: ONYX_KEYS.SIMPLE_KEY_2,
initialValue: false,
},
})(ViewWithCollections);
render(
<TestComponentWithOnyx
Expand All @@ -578,6 +582,7 @@ describe('withOnyxTest', () => {
onRender,
testObject: {isDefaultProp: true},
simple: 'initialValue',
simple2: false,
});
});
});
Expand Down

0 comments on commit 950e257

Please sign in to comment.