New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-atomic-store

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-atomic-store

Simple React store based on useSyncExternalStore

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

react-atomic-store

Install

npm install react-atomic-store

Usage

import { createStore } from 'react-atomic-store'

const { useStore } = createStore({ foo: 1, bar: true })

function Bar() {
  const { bar, setBar } = useStore()
  return (
    <>
      <p>bar: {bar.toString()}</p>
      <button
        onClick={() => {
          setBar(v => !v)
        }}
      >
        change bar
      </button>
    </>
  )
}

function App() {
  const { foo, setFoo, bar } = useStore()
  return (
    <div>
      foo: {foo}
      <button
        onClick={() => {
          setFoo(foo + 1)
        }}
      >
        add foo
      </button>
      <Bar />
    </div>
  )
}

API

Only one api: createStore

const { useStore, getStoreMethods, getStoreState, getStateSnapshot, subscribeStore } = createStore({
  foo: 1,
  bar: false,
})

Return value of createStore:

  • useStore

    get current store state and get/set methods

    function MyComp() {
      const { foo, setFoo, getFoo, bar, setBar, getBar } = useStore()
      return (
        <div
          onClick={() => {
            setFoo()
          }}
        >
          {foo}
        </div>
      )
    }
    
  • getStoreMethods

    get current store get/set methods

Keywords

react

FAQs

Package last updated on 25 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts