haithemT / valtio

πŸ’Š Valtio makes proxy-state simple

Home Page:https://codesandbox.io/s/valtio-simple-counter-qqljs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alt. Description

Valtio

npm i valtio makes proxy-state simple

Wrap your state object

import { proxy, useProxy } from 'valtio'

const state = proxy({ count: 0, text: 'hello' })

Mutate from anywhere

setInterval(() => {
  ++state.count
}, 1000)

React via useProxy

function Counter() {
  const snapshot = useProxy(state)
  return (
    <div>
      {snapshot.count}
      <button onClick={() => ++state.count}>+1</button>
    </div>
  )
}

And that's it!

About

πŸ’Š Valtio makes proxy-state simple

https://codesandbox.io/s/valtio-simple-counter-qqljs

License:MIT License


Languages

Language:TypeScript 80.6%Language:JavaScript 19.4%