MCPcopy Index your code
hub / github.com/react/react / initStoreFromUrlOrLocalStorage

Function initStoreFromUrlOrLocalStorage

compiler/apps/playground/lib/stores/store.ts:56–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54 * localStorage. Throw an error if Store is malformed.
55 */
56export function initStoreFromUrlOrLocalStorage(): Store {
57 const encodedSourceFromUrl = location.hash.slice(1);
58 const encodedSourceFromLocal = localStorage.getItem('playgroundStore');
59 const encodedSource = encodedSourceFromUrl || encodedSourceFromLocal;
60
61 /**
62 * No data in the URL and no data in the localStorage to fallback to.
63 * Initialize with the default store.
64 */
65 if (!encodedSource) return defaultStore;
66
67 const raw: any = decodeStore(encodedSource);
68
69 invariant(isValidStore(raw), 'Invalid Store');
70
71 // Make sure all properties are populated
72 return {
73 source: raw.source,
74 config: 'config' in raw && raw['config'] ? raw.config : defaultConfig,
75 showInternals: 'showInternals' in raw ? raw.showInternals : false,
76 };
77}

Callers 1

StoreProviderFunction · 0.90

Calls 2

decodeStoreFunction · 0.85
isValidStoreFunction · 0.85

Tested by

no test coverage detected