Skip to main content
By default, SublayProvider creates and manages its own isolated Redux store. This is the recommended approach for most projects — no Redux configuration required. If your application already has its own Redux store, we strongly recommend merging Sublay’s state into it using SublayIntegrationProvider. Running two separate Redux stores in the same React app is a common source of subtle bugs: React-Redux binds components to the nearest <Provider> in the tree, so hooks can silently read from the wrong store depending on where components are rendered.

When to Use This

If your app already has a Redux store, use SublayIntegrationProvider. This is the right path for virtually every app in that situation. The standalone SublayProvider is only appropriate for apps that don’t use Redux at all. The standalone provider creates its own internal store. When that coexists with your app’s store, React-Redux binds components to whichever <Provider> is closest in the tree — which means hooks silently read from the wrong store depending on where a component is rendered. These bugs are hard to spot and hard to trace. The only reason to use SublayProvider alongside an existing Redux store is if you have a specific, deliberate reason to keep the two stores completely separate and you fully understand the implications. For nearly everyone, that’s not the case.

Setup

Integration mode requires three changes to your existing store and one change to your provider setup.
1

Add Sublay reducers to your store

Import sublayReducers and sublayApiReducer from @sublay/react-js and add them to your store’s reducer map. The keys must be exactly sublay and sublayApi — the SDK’s internal selectors depend on these names.
2

Replace SublayProvider with SublayIntegrationProvider

Use SublayIntegrationProvider instead of SublayProvider. This provider does not create a Redux store — it expects your own <Provider> to already be in the tree above it.
Import it from your platform package@sublay/react-js, @sublay/react-native or @sublay/exponot from @sublay/core.Account persistence is carried by an AccountManager component that only the platform packages can supply, because the storage adapter is platform-specific. Core’s own SublayIntegrationProvider has no AccountManager: it works, but the account map lives only in memory, so stored accounts (and the per-device push state that rides on the same map) do not survive a relaunch. The platform packages’ version wraps core’s and mounts the right adapter for you.

Props

SublayIntegrationProvider accepts the same props as SublayProvider:
string
required
Your Sublay project ID.
string | null
A signed JWT for external authentication mode. See External Auth.

Exports Reference

All integration exports are available from @sublay/react-js:
The raw setActiveAccount, upsertAccount and removeAccount reducers are deliberately not exported. They only mutate local state: setActiveAccount can point the active id at an account that is not in the map, and removeAccount drops an account without signing it out server-side. Use activateStoredAccount and the useRemoveAccount hook, which perform the whole flow.

The Storage Contract

AccountStorage is the interface an AccountManager implements, and the platform packages supply one each. If you write your own, three rules govern it:
  • getAccountMap is tolerant. An unreadable, corrupt or unrecognized store resolves null rather than throwing. Nothing useful can be done with a read failure at the call sites, and a throw takes the whole bootstrap down.
  • setAccountMap and deleteAccountMap must reject when the write does not land. Logging the failure on the way out is fine; resolving anyway is not. The SDK awaits these writes and treats a resolved promise as “this is durably stored” — most consequentially for a rotated refresh token, where believing a failed write means re-presenting a revoked token and destroying that account’s whole token family.
  • No locking of your own is needed. Core serializes every call per projectId.
One project per app is the supported shape, and account storage enforces it: mounting a second provider for a different project id throws at mount, with a message naming both project ids. See One project per app.

Clearing Your Own State on an Account Change

Sublay dispatches resetAccountScopedState on every path that changes the active account — switching, removing, signing out, deleting an account, adding one, a direct sign-in while another account is active, and cross-tab sync. Its own feature slices return to their initial state on it. If you keep account-scoped data in your own slices, subscribe to the same signal instead of re-deriving when an account changed:
RTK Query caches are handled separately by sublayApi.util.resetApiState(), which the SDK dispatches alongside.

State Shape

When integrated, Sublay occupies two top-level keys in your store:
The sublay and sublayApi keys are required by Sublay’s internal selectors. Mounting the reducers under different keys will cause the SDK to malfunction.

TypeScript

Sublay exports SublayState if you need to type a state slice that references Sublay’s shape: