Blog>
Snippets

Initial Setup of TanStack Store in a React App

Showcase the initial steps to integrate TanStack Store into a React application, including store creation and providing it to the React component tree.
import { createStore, StoreProvider } from '@tanstack/react-store';
Imports createStore to create a new store and StoreProvider to provide the store to the React component tree.
const store = createStore({
  initialState: { count: 0 },
});
Creates a new store with an initial state containing a count property set to 0.
function App() {
  return (
    <StoreProvider store={store}>
      {/* Your app components go here */}
    </StoreProvider>
  );
}
Wraps the app components with the StoreProvider, passing the created store as a prop to make it available throughout the component tree.