npm.io
1.0.3 • Published 3 years ago

@hamidreza.nateghi/use-state

Licence
ISC
Version
1.0.3
Deps
1
Size
4 kB
Vulns
0
Weekly
0

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>
}

Keywords