Skip to content

Commit ae21134

Browse files
authored
fix(brownie): throw descriptive error when store not registered (#203)
1 parent 5297ee8 commit ae21134

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/brownie/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ function getOrCreateStore(key: string): StoreCache {
3030
let store = stores.get(key);
3131
if (!store) {
3232
const hostObject = getHostObject(key);
33+
if (!hostObject) {
34+
throw new Error(
35+
`[Brownie] Store "${key}" not found. ` +
36+
`Make sure to register it on the native side before accessing it from JS.\n\n` +
37+
`Swift example:\n` +
38+
` ${key}.register(${key}(...))\n\n` +
39+
`This should be called before React Native starts.`
40+
);
41+
}
3342
store = {
3443
hostObject,
35-
snapshot: hostObject?.unbox?.() ?? {},
44+
snapshot: hostObject.unbox?.() ?? {},
3645
listeners: new Set(),
3746
};
3847
stores.set(key, store);
@@ -85,7 +94,6 @@ export function setState<K extends keyof BrownieStores>(
8594
action: SetStateAction<BrownieStores[K]>
8695
): void {
8796
const store = getOrCreateStore(key as string);
88-
if (!store.hostObject) return;
8997

9098
const partial =
9199
typeof action === 'function'

0 commit comments

Comments
 (0)