--- id: createStoreContext title: createStoreContext --- ```ts function createStoreContext(): object; ``` Defined in: [packages/react-store/src/createStoreContext.tsx:40](https://github.com/TanStack/store/blob/main/packages/react-store/src/createStoreContext.tsx#L40) Creates a typed React context for sharing a bundle of atoms and stores with a subtree. The returned `StoreProvider` only transports the provided object through React context. Consumers destructure the contextual atoms and stores, then compose them with the existing hooks like [useSelector](useSelector.md), [useSelector](useSelector.md) and [useAtom](useAtom.md). The object shape is preserved exactly, so keyed atoms and stores remain fully typed when read back with `useStoreContext()`. ## Type Parameters ### TValue `TValue` *extends* `object` ## Returns `object` ### StoreProvider ```ts StoreProvider: (props) => ReactElement; ``` #### Parameters ##### props `object` & `object` #### Returns `ReactElement` ### useStoreContext ```ts useStoreContext: () => TValue; ``` #### Returns `TValue` ## Example ```tsx const { StoreProvider, useStoreContext } = createStoreContext<{ countAtom: Atom totalsStore: Store<{ count: number }> }>() function CountButton() { const { countAtom, totalsStore } = useStoreContext() const count = useSelector(countAtom) const total = useSelector(totalsStore, (state) => state.count) return ( ) } ``` ## Throws When `useStoreContext()` is called outside the matching `StoreProvider`.