Skip to content

Commit e525c29

Browse files
⚡ Optimize state initialization in hooks using lazy evaluation (#28)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com>
1 parent 321bcc6 commit e525c29

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/Squawk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export default function createStore<T>(initialState: Required<T>, useReduxDevToo
318318
* See documentation for `pending()` for more details
319319
*/
320320
usePending<T extends StoreProp>(...explicitContexts: T[]) {
321-
const [localPending, localDispatch] = useState(pendingState.get());
321+
const [localPending, localDispatch] = useState(() => pendingState.get());
322322

323323
const subscriber = useIfMounted((value: PendingState) => {
324324
localDispatch(value);
@@ -371,7 +371,7 @@ export default function createStore<T>(initialState: Required<T>, useReduxDevToo
371371
*/
372372
useSquawk<T extends StoreProp>(...explicitContexts: T[]): TStore {
373373
/** Initialize useState with the global state */
374-
const [localState, localDispatcher] = useState(globalState.get());
374+
const [localState, localDispatcher] = useState(() => globalState.get());
375375

376376
/** Define subscribe via callback to guarantee stable identity */
377377
const subscriber = useIfMounted((value: TStore) => {

0 commit comments

Comments
 (0)