This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

stateful-component
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

Stateful Component

Define components as pure state machines.

Demo

https://stateful-component.vercel.app/

Deploy with Vercel

Parameters

initialState: State

The initial state to use.

updateState: (State) => State | null

Accepts state as an argument, returns a modified form or null (to stop transition).

Children: (State) => ReactElement

Renders a component as a function of state.

Example

/**
 * This component increases as you press a button.
 */
<StatefulComponent initialState={{ count: 0 }}>
  {({ count, updateState }) => (
    <div>
      <button
        className="rounded-lg m-4 border-2 p-2"
        onClick={() => updateState({ count: count + 1 })}
      >
        Click me
      </button>
      <p>
        Count: <strong>{count}</strong>
      </p>
    </div>
  )}
</StatefulComponent>

Readme

Keywords

none

Package Sidebar

Install

npm i stateful-component

Weekly Downloads

0

Version

1.5.1

License

MIT

Unpacked Size

6.4 kB

Total Files

12

Last publish

Collaborators

  • ctjlewis