From e571da32fb3007d6cf2b8b4840a25e3b8fc5b80d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 28 Feb 2024 10:55:02 +0800 Subject: [PATCH 1/2] use initialValue when cached value is undefined --- lib/withOnyx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/withOnyx.js b/lib/withOnyx.js index 2d91424c..46971a39 100644 --- a/lib/withOnyx.js +++ b/lib/withOnyx.js @@ -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; } From e44fd24039f9188b5c729dccfa608b0aded19538 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 28 Feb 2024 10:55:07 +0800 Subject: [PATCH 2/2] add unit test --- tests/unit/withOnyxTest.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/withOnyxTest.js b/tests/unit/withOnyxTest.js index 6f6eba37..bf8724f2 100644 --- a/tests/unit/withOnyxTest.js +++ b/tests/unit/withOnyxTest.js @@ -561,6 +561,10 @@ describe('withOnyxTest', () => { key: ONYX_KEYS.SIMPLE_KEY, initialValue: 'initialValue', }, + simple2: { + key: ONYX_KEYS.SIMPLE_KEY_2, + initialValue: false, + }, })(ViewWithCollections); render( { onRender, testObject: {isDefaultProp: true}, simple: 'initialValue', + simple2: false, }); }); });