React 状态管理库 statty

码农软件 · 软件分类 · 常用JavaScript包 · 2019-04-04 23:29:48

软件介绍

statty 是一个小巧而又不引人注目的,用于 React 和 Preact 应用程序的状态管理库。

使用方法:

// 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'))

本文地址:https://codercto.com/soft/d/2881.html

数据结构与算法

数据结构与算法

2009-8 / 32.00元

《数据结构与算法》系统地介绍了数据结构的基本概念和基本算法,主要内容包括:绪论,线性表,栈与队列,串,数组、特殊矩阵和广义表,树,图,排序,查找,算法的分析与设计,实验与上机指导。《数据结构与算法》特别注重突出应用性和实践性,实例和习题丰富,并在附录中给出了各章习题的答案。 《数据结构与算法》适合作为应用型本科院校和成人教育计算机专业数据结构课程的教材,也可作为数据结构培训班的教材以及软件从......一起来看看 《数据结构与算法》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码