0.15.3 • Published 2 years ago

react-redux-await-control v0.15.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Redux Await Control

npm version npm downloads

Working with redux can be very verbose. React Redux Await Control intends to help you deal with it.

Installation

# If you use npm:
npm i react-redux-await-control

# Or if you use Yarn:
yarn add react-redux-await-control

Usage

reducers.js

import { combineReducers } from 'redux';
import AwaitControl from 'react-redux-await-control';

import authReducer from './auth';
import todoReducer from './todo';

const reducers = AwaitControl.init().mix({
  authReducer,
  todoReducer,
});

export default combineReducers({ ...reducers });

action.js

...
import { createAsyncAction } from 'react-redux-await-control';
...

export const removeTodo = createAsyncAction('REMOVE_TODO');
# in this way the information passed by parameters on success or failure is saved.
export const listTodo = createAsyncAction('LIST_TODO', { saveResult: true });

component.js

import React, { useEffect } from 'react';
import { useAwaitControl } from 'react-redux-await-control';
...
import { listTodos } from '../store/action';

export default function Component() {
  const listTodosControl = useAwaitControl(listTodos);

  useEffect(() => {
    listTodosControl.start();
    return () => listTodosControl.cancel();
  }, []);

  if (listTodosControl.isRunning()) {
    return <Loading />;
  }

  if (listTodosControl.hasFailure()) {
    return <Error />;
  }

  return (
    <List>
       {
          listTodosControl.result().map(
            todo => <Item key={todo.id} data={todo} />
          )
       }
    </List>
  );
}

API Reference

AwaitControl

MethodParametersReturn TypeDescription
initconfig?: AwaitControlInitializerAwaitControlInitialize the library
getControl-AwaitControlGet the AwaitControl single object
mixreducers: ReducersMapObjectReducersMapObjectcombines the reducers of the project with the reducer that belongs to the library

AwaitControlInitializer

PropertyTypeDescription
keyReducerStringChange the default keyReducer

AsyncActionControl

MethodParametersReturn TypeDescription
start
cancel
success
failure
clear
PropertyTypeDescription
label
rawKey

AwaitControlHook

MethodParametersReturn TypeDescription
start
cancel
success
failure
clear
result
isRunning
wasCancelled
hasFailure
isSuccessful

License

MIT

0.15.3

2 years ago

0.13.0

2 years ago

0.14.0

2 years ago

0.15.0

2 years ago

0.15.1

2 years ago

0.15.2

2 years ago

0.12.5

2 years ago

0.12.4

3 years ago

0.12.0

3 years ago

0.11.1

3 years ago

0.12.1

3 years ago

0.12.2

3 years ago

0.12.3

3 years ago

0.11.0

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.7.5

3 years ago

0.7.2

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.4.0

3 years ago

0.7.0

3 years ago

0.6.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago