Skip to content

glitch-txs/create-react-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Create global useState's to avoid prop drilling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published