Open History to see the last commit
1---
2title: Quick Start
3id: quick-start
4---
5
6The basic Solid app example to get started with the TanStack Solid-store.
7
8```jsx
9import { createStore, useSelector } from '@tanstack/solid-store';
10
11// You can instantiate the store outside of Solid components too!
12export const store = createStore({
13 cats: 0,
14 dogs: 0
15})
16
17export const Display = (props) => {
18 const count = useSelector(store, (state) => state[props.animals]);
19 return (
20 <span>
21 {props.animals}: {count()}
22 </span>
23 );
24}
25
26export const Button = (props) => {
27 return (
28 <button
29 onClick={() => {
30 store.setState((state) => {
31 return {
32 ...state,
33 [props.animals]: state[props.animals] + 1
34 }
35 })
36 }}
37 >
38 Increment
39 </button>
40 )
41}
42
43const App = () => {
44 return (
45 <div>
46 <h1>How many of your friends like cats or dogs?</h1>
47 <p>
48 Press one of the buttons to add a counter of how many of your friends
49 like cats or dogs
50 </p>
51 <Button animals="dogs" />
52 <Display animals="dogs" />
53 <Button animals="cats" />
54 <Display animals="cats" />
55 </div>
56 );
57};
58
59export default App;
60```
61
62`useStore` remains available as a deprecated alias to `useSelector`.