Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 707 Bytes

README.md

File metadata and controls

37 lines (26 loc) · 707 Bytes

Create React State

Install npm bundle size

pnpm add create-react-state

Create a useState

You can create a "useState" outside React components

import { createState } from 'create-react-state'

export const useCount = createState(0)

Use in any React Component

import useCount in any component

import './App.css'
import { createState } from 'create-react-state'

export const useCount = createState(0)

export default function App() {
  const [count, setCount] = useCount()

  return (
    <button onClick={() => setCount((count) => count + 1)}>
      count is {count}
    </button>
  )
}