Chok’s React Utilities
    Preparing search index...

    Class SharedState<T>

    Please use sharedState() instead.

    Type Parameters

    • T
    Index

    Constructors

    Properties

    initDone: boolean = false
    initStarted: boolean = false
    readyPromise: Promise<void>
    setValueBounded: Dispatch<SetStateAction<T>>

    Methods

    • Remove the value of the shared state. Actually this just sets the value back to the given default value.

      Returns void

    • Get a value directly from the store. Returns undefined if there is no backing store.

      Returns Promise<T | undefined>

    • Get the value of the shared state. getSnapshot function — must return same ref if value unchanged. Note that this would return the default value if data init from store is not completed yet.

      Returns T

    • Returns true if there is a backing store.

      Returns boolean

    • Initial default handling.

      Returns Promise<void>

    • Set a value directly into the store. Does nothing if there is no backing store.

      Warning: If you want to set the value properly, you should use setValue() instead which also updates the in-memory copy.

      Parameters

      • value: T

      Returns Promise<void>

    • Set the value of the shared state.

      Parameters

      • next: SetStateAction<T>

      Returns void

    • subscribe function required by useSyncExternalStore.

      Parameters

      • subscriber: () => void

      Returns () => void