<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          stattyReact 狀態(tài)管理庫

          聯(lián)合創(chuàng)作 · 2023-09-22 03:15

          statty 是一個(gè)小巧而又不引人注目的,用于 React 和 Preact 應(yīng)用程序的狀態(tài)管理庫。

          使用方法:

          // https://codesandbox.io/s/rzpxx0w34
          import React from 'react'
          import { render } from 'react-dom'
          import { Provider, State } from 'statty'
          import inspect from 'statty/inspect'
          
          // selector is a function that returns a slice of the state
          // if not specified it defaults to f => f
          const selector = state => ({ count: state.count })
          
          // updaters
          
          // updaters MUST be pure and return a complete new state,
          // like Redux reducers
          const onDecrement = state => 
            Object.assign({}, state, { count: state.count - 1 })
          
          const onIncrement = state =>
            Object.assign({}, state, { count: state.count + 1 })
          
          // Counter uses a <State> component to access the state
          // and the update function used to execute state mutations
          const Counter = () => (
            <State
              select={selector}
              render={({ count }, update) => (
                <div>
                  <span>Clicked: {count} times </span>
                  <button onClick={() => update(onIncrement)}>+</button>{' '}
                  <button onClick={() => update(onDecrement)}>-</button>{' '}
                </div>
              )}
            />
          )
          
          // initial state
          const initialState = {
            count: 0
          }
          
          // The <Provider> component is supposed to be placed at the top
          // of your application. It accepts the initial state and an inspect function
          // useful to log state mutatations during development
          // (check your dev tools to see it in action)
          const App = () => (
            <Provider state={initialState} inspect={inspect}>
              <Counter />
            </Provider>
          )
          
          render(<App />, document.getElementById('root'))
          瀏覽 24
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  九九热在线精品视频 | 插吧,综合网 | 亚洲无码精品在线观看 | 欧美亚洲中文日韩 | 蜜桃网站在线观看 |