# with-xstate

> HOC to handle xState actions

Latest version **0.0.6** (published 2019-04-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install with-xstate
pnpm add with-xstate
yarn add with-xstate
bun add with-xstate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2019-04-24 |
| First published | 2018-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Andres Alarcon |
| Maintainers | maximux13 |
| Keywords | react, xstate, redux, HOC |

## Links

- npm: https://www.npmjs.com/package/with-xstate
- Repository: https://github.com/maximux13/with-xstate
- Homepage: https://github.com/maximux13/with-xstate#readme
- Issues: https://github.com/maximux13/with-xstate/issues
- npm.io page: https://npm.io/package/with-xstate

## Dependencies (4)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.2
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [babel-preset-env](https://npm.io/package/babel-preset-env.md) ^1.7.0
- [babel-preset-react-app](https://npm.io/package/babel-preset-react-app.md) ^3.1.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2019-04-24
- 0.0.5 — 2019-01-25
- 0.0.4 — 2018-10-05
- 0.0.3 — 2018-10-05
- 0.0.2 — 2018-10-05
- 0.0.1 — 2018-10-04

## README

# (HOC) With XState


## Installation

```bash
npm install with-xstate
or
yarn add with-xstate
```

## Require

* [xstate](https://github.com/davidkpiano/xstate)

## Usage

In order to use `withXState` first pass the machine state through a prop to your component and then wrap it


### mapActionsToXState((dispatch) => {...})

takes a function that should return and object that contains a key, value pair, where each key is a machine state and its value should be another object that contain a key, value pair with the actions and the functions that should be execute once xstate added to the next state.

**NOTE** `mapActionsToXState` pass `dispatch` as optionally prop so you can dispatch redux actions in your state actions.

```js
import { Machine } from 'xstate';
import withXState from 'with-xstate';
import Component from './Component';

const toggleMachine = Machine({
  initial: 'inactive',
  states: {
    inactive: {
      on: {
        TOGGLE: 'active',
        onEntry: ['fetchQuery']
      }
    },
    active: { on: { TOGGLE: 'inactive' } }
  }
});

const mapActionsToXState = () => ({
  'machineState': {
    fetchQuery: () => {
      console.log('fetch...')
    }
  }
});

const WithXStateComponent = withXState(mapActionsToXState)(Component);

<WithXStateComponent machineState={machine} />
```

---
_Source: https://npm.io/package/with-xstate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
