pnpm add create-react-state
You can create a "useState" outside React components
import { createState } from 'create-react-state'
export const useCount = createState(0)
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>
)
}