@hamidreza.nateghi/use-state
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

useState as a store

You can try a live demo here.

npm install @hamidreza.nateghi/use-state # or yarn add @hamidreza.nateghi/use-state

First create a store

import create from '@hamidreza.nateghi/use-state'

const useState = create({
  count: 0,
  todos: [],
  theme: 'dark',
})

Then bind your components, and that's it!

function App() {
  const [theme] = useState('theme')
  return <h1>Theme: {theme}</h1>
}

function ThemeController() {
  const [theme, setTheme] = useState('theme')
  return <button onClick={() => setTheme('light')}>{theme}</button>
}

Package Sidebar

Install

npm i @hamidreza.nateghi/use-state

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

4.37 kB

Total Files

6

Last publish

Collaborators

  • hamidreza.nateghi