Basic TanStack Config Setup
Demonstrate how to initialize TanStack Config in a JavaScript project, highlighting the simplicity of setting basic configurations.
import { createStore } from '@tanstack/store-react';
// Define initial state
const initialState = {
counter: 0
};
// Create a store
const store = createStore({
initialState
});
This code imports the createStore function from the @tanstack/store-react package and uses it to create a new store with an initial state that includes a counter set to 0.
store.setState({ counter: store.getState().counter + 1 });
This line demonstrates how to update the store's state, in this case incrementing the counter by 1.
const counterValue = store.getState().counter;
This line retrieves the current value of the counter from the store's state.