MCPcopy Index your code
hub / github.com/codemask-labs/stan-js

github.com/codemask-labs/stan-js @v1.9.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.9.1 ↗ · + Follow
75 symbols 221 edges 55 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TypeScript React ReactNative platform - ssr MIT NPM Version NPM Downloads

stan-js

Overview

stan-js is a lightweight and flexible state management library designed for use in React, React Native and even vanilla-js applications. It simplifies the process of managing state in your application by providing a simple createStore function. This package aims to offer a straightforward solution for state management without the need for extensive type definitions or repetitive code.

Features

  • ⚡️ Performance and minimal re-renders
  • ✍️ Simple configuration
  • ⚛️ Out of the box React integration
  • 💾 Built in data persistence
  • 🚀 Amazing typescript IntelliSense
  • 🪝 Easy access to all store values
  • 🪶 Very lightweight
  • 🥳 No dependencies
  • 🛡️ 100% Test coverage

Installation

Install package using preferred package manager:

npm install stan-js
yarn add stan-js
pnpm add stan-js
bun add stan-js

Demos

React

Open in repo Open in StackBlitz

Astro + React

Open in repo Open in StackBlitz

Next.js SSR

Open in repo Open in StackBlitz

Getting Started

Create a store with initial state:

You can think of a store as your app state. You can define multiple keys/values, each key will create separated subscription (more explained here). If you want to persist the value - you can simply wrap it in Synchronizer

import { createStore } from 'stan-js'
import { storage } from 'stan-js/storage'

export const { useStore } = createStore({
    count: 0,
    get doubleCount() {
        return this.count * 2
    }, 
    user: storage(''),
    selectedLanguage: 'en-US',
    unreadNotifications: [] as Array<Notification>
})

Use the returned hook in your React component:

import { useStore } from './store'

const App = () => {
    const { count, user, setCount } = useStore()

    return (



            <h1>Hello {user}!</h1>


Count: {count}


            <button onClick={() => setCount(prev => prev + 1)}>Increment</button>
            <button onClick={() => setCount(prev => prev - 1)}>Decrement</button>



    )
}

Check out our Docs for more information and examples.

Extension points exported contracts — how you extend this code

ButtonProps (Interface)
(no doc)
examples/react/src/components/ui/button.tsx
Register (Interface)
(no doc)
examples/tanstack-start/app/router.tsx

Core symbols most depended-on inside this repo

createStore
called by 32
src/vanilla/createStore.ts
useStore
called by 19
src/scoped.tsx
getState
called by 18
src/vanilla/createStore.ts
effect
called by 9
src/vanilla/createStore.ts
cn
called by 8
examples/react/src/lib/utils.ts
equal
called by 7
src/utils.ts
createScopedStore
called by 7
src/scoped.tsx
isLocalStorageAvailable
called by 7
src/storage/factory.ts

Shape

Function 73
Interface 2

Languages

TypeScript100%

Modules by API surface

src/vanilla/createStore.ts9 symbols
src/tests/createStore.test.tsx9 symbols
examples/react/src/App.tsx9 symbols
src/utils.ts8 symbols
src/scoped.tsx6 symbols
src/createStore.ts6 symbols
src/tests/synchronizer.test.ts4 symbols
src/tests/scoped.test.tsx3 symbols
src/storage/factory.ts3 symbols
src/storage/mmkvFactory.ts2 symbols
examples/tanstack-start/app/router.tsx2 symbols
examples/react/src/store.ts2 symbols

For agents

$ claude mcp add stan-js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page