0.1.4 • Published 1 year ago

@coalesce.dev/store-client-react v0.1.4

Weekly downloads
-
License
GNU GPLv3
Repository
-
Last release
1 year ago

Shared Store - Client - React

@coalesce.dev/store-client-react

This package provides React hooks and components to use with @coalesce.dev/store-client.

Usage

Wrap your application component with a SharedStoreProvider at a higher level than any usage:

<SharedStoreProvider store={storeClient}>
  <App />
</SharedStoreProvider>

Selecting State

Values can be retrieved from the store using the useSharedValue hook. For easier usage, a store specific hook can be implemented:

export function useMySharedValue<S extends Selector>(selector: S) {
  return useSharedValue<StoreState /* set your store's state type here */, S>(
    selector
  );
}

Mutating State

Values can be mutated using the useSharedState hook. Similarly, a store specific hook can also be implemented:

export function useMySharedState<S extends Selector>(selector: S) {
  return useSharedState<StoreState, S>(selector);
}

This hook returns a tuple containing the current state and a callback to change the value. Note that this callback is asynchronous and changes will not be immediately reflected.

To get a reference to the store, use the useSharedStore hook.

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago