little-state-machine-devtools
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published
Little State Machine - React Hooks for state management

Little State Machine Devtools

State management made super simple

Tweet  npm downloads npm

📦 Installation

$ npm install little-state-machine-devtools

🖥 Demo

Check out the Demo.
import { DevTool } from 'little-state-machine-devtools'

<StateMachineProvider>
 {process.env.NODE_ENV !== 'production' && <DevTool />}
</StateMachineProvider>

📖 Example

📋 app.js

import React from 'react'
import yourDetail from './yourDetail'
import YourComponent from './yourComponent'
import { StateMachineProvider, createStore } from 'little-state-machine'
import { DevTool } from 'little-state-machine-devtools'

// The following code is for React Native usage
// import { AsyncStorage } from "react-native";
// setStorageType(AsyncStorage);

// create your store
createStore({
  yourDetail,
});

export default () => {
  return (
    <StateMachineProvider>
      {process.env.NODE_ENV !== 'production' && <DevTool />}
      <YourComponent />
    </StateMachineProvider>
  )
}

📋 yourComponent.js

import React from 'react'
import { updateName } from './action.js'
import { useStateMachine } from 'little-state-machine'

export default function YourComponent() {
  const {
    action,
    state: { yourDetail: { name } },
  } = useStateMachine(updateName);

  return <div onClick={() => action({ name: 'bill' })}>{name}</div>
}

📋 yourDetail.js

export default {
  name: 'test',
}

📋 action.js

export function updateName(state, payload) {
  return {
    ...state,
    yourDetail: {
      ...state.yourDetail,
      ...payload,
    },
  }
}

Readme

Keywords

Package Sidebar

Install

npm i little-state-machine-devtools

Weekly Downloads

1,223

Version

2.0.2

License

MIT

Unpacked Size

58.1 kB

Total Files

14

Last publish

Collaborators

  • bluebill1049