📄 tanstack/store/latest/docs/framework/solid/examples/simple

File: simple.md | Updated: 11/15/2025

Source: https://tanstack.com/store/latest/docs/framework/solid/examples/simple



TanStack

Store v0v0

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

Solid logo

Solid

Version

Latest

Search...

+ K

Menu

Getting Started

API Reference

Examples

Framework

Solid logo

Solid

Version

Latest

Menu

Getting Started

API Reference

Examples

Solid Example: Simple

Github StackBlitz CodeSandbox

===============================================================================================================================================================================================================================================================================================================================================================================================

Code ExplorerCode

Interactive SandboxSandbox

  • src

    • index.tsx file iconindex.tsx

    • vite-env.d.ts file iconvite-env.d.ts

  • .gitignore file icon.gitignore

  • README.md file iconREADME.md

  • index.html file iconindex.html

  • package.json file iconpackage.json

  • tsconfig.json file icontsconfig.json

  • vite.config.ts file iconvite.config.ts

tsx

import { Store, useStore } from '@tanstack/solid-store'
import { render } from 'solid-js/web'

// You can instantiate a Store outside of Solid components too!
export const store = new Store({
  cats: 0,
  dogs: 0,
})

interface DisplayProps {
  animals: 'dogs' | 'cats'
}

export const Display = (props: DisplayProps) => {
  const count = useStore(store, (state) => state[props.animals])
  return (
    <div>
      {props.animals}: {count()}
    </div>
  )
}

interface ButtonProps {
  animals: 'dogs' | 'cats'
}

export const Button = (props: ButtonProps) => {
  return (
    <button
      onClick={() => {
        store.setState((state) => {
          return {
            ...state,
            [props.animals]: state[props.animals] + 1,
          }
        })
      }}
    >
      Increment
    </button>
  )
}

const App = () => {
  return (
    <div>
      <h1>How many of your friends like cats or dogs?</h1>
      <p>
        Press one of the buttons to add a counter of how many of your friends
        like cats or dogs
      </p>
      <Button animals="dogs" />
      <Display animals="dogs" />
      <Button animals="cats" />
      <Display animals="cats" />
    </div>
  )
}

const root = document.getElementById('root')

render(() => <App />, root!)


import { Store, useStore } from '@tanstack/solid-store'
import { render } from 'solid-js/web'

// You can instantiate a Store outside of Solid components too!
export const store = new Store({
  cats: 0,
  dogs: 0,
})

interface DisplayProps {
  animals: 'dogs' | 'cats'
}

export const Display = (props: DisplayProps) => {
  const count = useStore(store, (state) => state[props.animals])
  return (
    <div>
      {props.animals}: {count()}
    </div>
  )
}

interface ButtonProps {
  animals: 'dogs' | 'cats'
}

export const Button = (props: ButtonProps) => {
  return (
    <button
      onClick={() => {
        store.setState((state) => {
          return {
            ...state,
            [props.animals]: state[props.animals] + 1,
          }
        })
      }}
    >
      Increment
    </button>
  )
}

const App = () => {
  return (
    <div>
      <h1>How many of your friends like cats or dogs?</h1>
      <p>
        Press one of the buttons to add a counter of how many of your friends
        like cats or dogs
      </p>
      <Button animals="dogs" />
      <Display animals="dogs" />
      <Button animals="cats" />
      <Display animals="cats" />
    </div>
  )
}

const root = document.getElementById('root')

render(() => <App />, root!)

Functions / useStore

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics