Skip to content
module@warp-drive/react

Function StoreProvider() ​

ts
function StoreProvider($props: StoreProviderProps): Element;

Defined in: -private/store-provider.tsx:129

Provides a Store to its children, which read it with useStore. <Request /> uses it when no store prop is given.

Pass either store, an existing Store instance, or Store, a Store class the provider creates an instance of for you. See StoreProviderProps.

For where this fits in app setup, see Provide the Store in React.

Parameters ​

$props ​

StoreProviderProps

Returns ​

Element

Example ​

tsx
import { StoreProvider } from "@warp-drive/react";
import AppStore from "./services/store";

export function App() {
  return (
    <StoreProvider Store={AppStore}>
      <UserPreview id="1" />
    </StoreProvider>
  );
}

To provide a store created outside React, such as one a host app already uses, pass the instance instead:

tsx
import { StoreProvider } from "@warp-drive/react";
import { store } from "./services/store";

root.render(
  <StoreProvider store={store}>
    <UserPreview id="1" />
  </StoreProvider>
);

Released under the MIT License.