MCPcopy Index your code
hub / github.com/QuiiBz/particule

github.com/QuiiBz/particule @0.0.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.0.4 ↗ · + Follow
38 symbols 108 edges 31 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
<h1 align="center">particule</h1>







<a href="https://github.com/QuiiBz/particule/actions">
    <img src="https://github.com/QuiiBz/particule/workflows/CI/badge.svg" />
</a>
<a href="https://github.com/QuiiBz/particule/blob/main/LICENSE">
    <img src="https://img.shields.io/badge/Licence-MIT-blue" />
</a>

Fine-grained atomic React state management library

yarn add particule


Particule is an atomic React state management library inspired by the best of Recoil, Jotai and Redux. You can choose which component subscribe to which state and so avoid useless re-render and computations.

✨ Features

  • Super-easy API
  • TypeScript ready
  • Suspense support
  • Minimal footprint (1kB gzipped)
  • Hooks to add functionality

🚀 Examples

Basic

const textAtom = atom('Hello world!')

function App() {
  const [text, setText] = useAtom(textAtom)

  return (
    <>


{text}


      <button onClick={() => setText('Updated!')}>Update</button>
    </>
  )
}

Fine-grained

const textAtom = atom('Hello world!')

function Text() {
  const text = useGetAtom(textAtom)

  return 

{text}


}

// Won't re-render!
function Button() {
  const setText = useSetAtom(textAtom)

  return <button onClick={() => setText('Updated!')}>Update</button>
}

// Won't re-render!
function App() {
  return (
    <>
      <Text />
      <Button />
    </>
  )
}

Composition

const eurosAtom = atom(10)
const dollarsAtom = atom(get => get(eurosAtom) * 1.15)

function App() {
  const [euros, setEuros] = useAtom(eurosAtom)
  const [dollars, setDollars] = useAtom(dollarsAtom)

  return (
    <>
      <input onChange={({ target }) => setEuros(target.value)} value={euros} />
      <input onChange={({ target }) => setDollars(target.value)} value={dollars} />
    </>
  )
}

Suspense

const nameAtom = atom(async () => {
  const json = await (await fetch("https://randomuser.me/api/")).json();

  return json.results[0].name.first;
});

function Name() {
  const name = useGetAtom(nameAtom)

  return 

My name is {name}


}

function App() {
  return (
    <Suspense fallback='Loading...'>
      <Name />
    </Suspense>
  )
}

Dispatch

const counterAtom = atom(0)
const dispatchCounter = dispatch(counterAtom, value => ({
  increment: (newValue: number) => value + newValue,
  decrement: (newValue: number) => value - newValue,
}))

function App() {
  const counter = useGetAtom(counterAtom)

  return (
    <>


{counter}


      <button onClick={() => dispatchCounter('increment', 1)}>Increment</button>
      <button onClick={() => dispatchCounter('decrement', 1)}>Decrement</button>
    </>
  )
}

Custom atom with hooks

const noZeroAtom = createAtom({
  beforeValueSet: (_, value) => {
    if (value === 0) {
      throw new Error('Cannot set value to 0')
    }

    return value
  }
})

const counterAtom = noZeroAtom(3)

function App() {
  const [count, setCount] = useAtom(counterAtom)

  return (
    <>


{count}


      <button onClick={() => setCount(count => count - 1)}>Reduce</button>
    </>
  )
}

📚 Documentation

See the website at particule.vercel.app. Hosted on Vercel.

License

MIT

Extension points exported contracts — how you extend this code

Props (Interface)
(no doc)
__tests__/test-util.tsx
State (Interface)
(no doc)
__tests__/test-util.tsx

Core symbols most depended-on inside this repo

atom
called by 28
src/atoms/atom.ts
useAtom
called by 23
src/atoms/hooks.ts
useGetAtom
called by 10
src/atoms/hooks.ts
get
called by 6
src/atoms/atom.ts
dispatch
called by 4
src/atoms/dispatch.ts
createAtom
called by 3
src/atoms/createAtom.ts
setAtomValue
called by 3
src/atoms/atom.ts
useHistoryAtom
called by 3
src/helpers/history.ts

Shape

Function 30
Method 3
Class 2
Interface 2
Enum 1

Languages

TypeScript100%

Modules by API surface

__tests__/test-util.tsx8 symbols
src/atoms/atom.ts7 symbols
src/atoms/hooks.ts3 symbols
src/utils/helpers.ts2 symbols
src/helpers/reset.ts2 symbols
src/helpers/history.ts2 symbols
src/utils/suspense.ts1 symbols
src/types.ts1 symbols
src/helpers/localStorage.ts1 symbols
src/atoms/dispatch.ts1 symbols
src/atoms/createAtom.ts1 symbols
site/pages/_app.tsx1 symbols

For agents

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

⬇ download graph artifact

Ask about this repo answers extend the page