Initializing a TanStack Store
Shows how to create and initialize a TanStack Store in a JavaScript application, including setting initial state values.
import { createStore } from '@tanstack/store';
const initialState = {
todos: []
};
export const store = createStore({
initialState
});
This code imports the createStore function from the '@tanstack/store' package and uses it to create a new store. The 'initialState' object defines the initial state of the store, which in this case contains an empty array of 'todos'. The 'createStore' function is then called with an object that includes the 'initialState', resulting in the creation of the store. The created store is exported for use in other parts of the application.