7.2.1 • Published 7 months ago

react-states v7.2.1

Weekly downloads
238
License
MIT
Repository
github
Last release
7 months ago

react-states

Explicit states for predictable user experiences

Install

npm install react-states

Introduction to react-states

react-states

Examples

Documentation

Values

  • "It is just a reducer"
  • Simple utilities
  • Enhanced type safety
  • Reducer does not express side effects

Learn by example

Instead of expressing your state implicitly:

type State = {
  isLoading: boolean;
  error: string | null;
  data: string[];
};

You can do so explicitly:

type State =
  | {
      state: 'NOT_LOADED';
    }
  | {
      state: 'LOADING';
    }
  | {
      state: 'LOADED';
      data: string[];
    }
  | {
      state: 'ERROR';
      error: string;
    };

With explicit states you can guard what actions are valid in what states using transition:

import { transition } from 'react-states';

const reducer = (prevState: State, action: Action) =>
  transition(prevState, action, {
    NOT_LOADED: {
      FETCH: () => ({
        state: 'LOADING',
      }),
    },
    LOADING: {
      FETCH_SUCCESS: (_, { data }) => ({
        state: 'LOADED',
        data,
      }),
      FETCH_ERROR: (_, { error }) => ({
        state: 'ERROR',
        error,
      }),
    },
    LOADED: {},
    ERROR: {},
  });

With additional utilities like createStates, createActions and match you will increase safety and reduce boilerplate in your code.

7.2.1

7 months ago

6.26.2-next-fix2

2 years ago

8.0.0-rc1

2 years ago

8.0.0-rc7

2 years ago

8.0.0-rc6

2 years ago

8.0.0-rc9

2 years ago

8.0.0-rc8

2 years ago

8.0.0-rc3

2 years ago

8.0.0-rc2

2 years ago

8.0.0-rc5

2 years ago

8.0.0-rc4

2 years ago

6.26.2-next-fix

2 years ago

7.0.0

2 years ago

7.0.4

2 years ago

7.0.3

2 years ago

7.0.2

2 years ago

7.0.1

2 years ago

8.0.0-rc13

2 years ago

8.0.0-rc10

2 years ago

8.0.0-rc11

2 years ago

8.0.0-rc12

2 years ago

7.1.1

2 years ago

7.1.0

2 years ago

6.4.0

2 years ago

7.2.0

2 years ago

14.2.0-next

2 years ago

13.1.0-next

2 years ago

15.0.2-next

2 years ago

14.1.4-next

2 years ago

6.0.0

2 years ago

14.1.0-next

2 years ago

14.0.1-next

2 years ago

15.0.0-next

2 years ago

14.1.2-next

2 years ago

6.1.0

2 years ago

13.0.0-next

2 years ago

6.2.5

2 years ago

6.2.4

2 years ago

6.2.6

2 years ago

14.1.5-next

2 years ago

6.2.1

2 years ago

15.0.4-next

2 years ago

6.2.0

2 years ago

6.2.3

2 years ago

6.2.2

2 years ago

6.3.0

2 years ago

14.0.0-next

2 years ago

14.1.3-next

2 years ago

14.1.1-next

2 years ago

14.0.2-next

2 years ago

15.3.0-next

2 years ago

15.1.0-next

2 years ago

10.0.0-next

2 years ago

12.2.2-next

2 years ago

10.3.0-next

2 years ago

10.5.1-next

2 years ago

10.4.1-next

2 years ago

12.1.1-next

2 years ago

11.0.0-next

2 years ago

12.0.0-next

2 years ago

12.1.0-next

2 years ago

12.2.0-next

2 years ago

12.2.1-next

2 years ago

10.2.0-next

2 years ago

10.1.0-next

2 years ago

10.3.1-next

2 years ago

9.7.2-next

2 years ago

9.8.0-next

2 years ago

9.7.1-next

2 years ago

9.7.0-next

3 years ago

9.6.0-next

3 years ago

9.3.0-next

3 years ago

9.0.0-next

3 years ago

9.5.0-next

3 years ago

9.1.0-next

3 years ago

9.2.0-next

3 years ago

9.4.0-next

3 years ago

8.0.0-next

3 years ago

7.4.2-next

3 years ago

7.4.1-next

3 years ago

7.3.0-next

3 years ago

7.4.0-next

3 years ago

7.2.0-next

3 years ago

7.1.4-next

3 years ago

7.1.3-next

3 years ago

7.1.1-next

3 years ago

7.1.0-next

3 years ago

7.0.0-next

3 years ago

7.1.2-next

3 years ago

7.1.5-next

3 years ago

6.30.1-next

3 years ago

6.30.0-next

3 years ago

6.30.2-next

3 years ago

6.28.2-next

3 years ago

6.29.0-next

3 years ago

6.28.0-next

3 years ago

6.28.1-next

3 years ago

6.28.3-next

3 years ago

6.27.12-next

3 years ago

6.27.1-next

3 years ago

6.27.11-next

3 years ago

6.27.7-next

3 years ago

6.27.8-next

3 years ago

6.27.0-next

3 years ago

6.27.9-next

3 years ago

6.27.6-next

3 years ago

6.27.10-next

3 years ago

6.27.5-next

3 years ago

6.27.2-next

3 years ago

6.27.3-next

3 years ago

6.27.4-next

3 years ago

6.23.1-next

3 years ago

6.17.2-next

3 years ago

6.26.0-next

3 years ago

6.15.0-next

3 years ago

6.6.0-next

3 years ago

6.2.0-next

3 years ago

6.3.0-next

3 years ago

6.14.0-next

3 years ago

6.11.0-next

3 years ago

6.10.0-next

3 years ago

6.24.2-next

3 years ago

6.20.2-next

3 years ago

6.26.1-next

3 years ago

6.24.1-next

3 years ago

6.8.2-next

3 years ago

6.15.1-next

3 years ago

6.20.1-next

3 years ago

6.25.0-next

3 years ago

6.17.3-next

3 years ago

6.7.0-next

3 years ago

6.19.0-next

3 years ago

6.18.0-next

3 years ago

6.8.0-next

3 years ago

6.9.0-next

3 years ago

6.24.0-next

3 years ago

6.23.0-next

3 years ago

6.22.0-next

3 years ago

6.21.0-next

3 years ago

6.20.0-next

3 years ago

6.17.1-next

3 years ago

6.19.1-next

3 years ago

6.8.1-next

3 years ago

6.25.1-next

3 years ago

6.2.1-next

3 years ago

6.8.3-next

3 years ago

6.17.0-next

3 years ago

6.13.0-next

3 years ago

6.12.0-next

3 years ago

6.1.0-next

3 years ago

6.20.3-next

3 years ago

6.16.0-next

3 years ago

6.5.0-next

3 years ago

6.4.0-next

3 years ago

6.0.0-next

3 years ago

6.26.2-next

3 years ago

6.20.4-next

3 years ago

6.20.6-next

3 years ago

6.20.5-next

3 years ago

5.3.0

3 years ago

5.1.0-next

3 years ago

5.2.2-next

3 years ago

5.2.1-next

3 years ago

5.4.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

5.2.0-next

3 years ago

4.1.0

3 years ago

4.0.0

3 years ago

4.7.0-next

3 years ago

4.6.0-next

3 years ago

4.5.0-next

3 years ago

4.4.2-next

3 years ago

4.4.1-next

3 years ago

4.4.3-next

3 years ago

4.4.0-next

3 years ago

4.3.0-next

3 years ago

4.1.0-next

3 years ago

4.2.0-next

3 years ago

4.0.0-next

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.4.2

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.2

3 years ago

2.1.9

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.4-next

3 years ago

2.1.2

3 years ago

2.1.0-next

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.2.2-next

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago