0.1.2 • Published 5 years ago

react-redux-guard v0.1.2

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

react-redux-guard

protect those containers from breaking when state needs data

Getting Started

basic usage with protect and required params:

  • guard : [Function] - handler that detects and resolves an invalid state
  • mstp - mapStateToProps for connect
  • mdtp - mapDispatchToProps for connect
import { protect, inSuspense } from "react-redux-guard";

const guard = props => {
  if (!props.hasProfile) {
    inSuspense(props.fetchProfile);
  }
};

const mstp = state => ({
  hasProfile: selectors.hasProfile(state)
});
const mdtp = dispatch => ({
  fetchProfile: done => dispatch(actions.fetchProfile(done))
});

ProfileViewer.Protected = protect(guard, mstp, mdtp)(ProfileViewer.Connected);

define more than one guard config to protectAll

import { protectAll, inSuspense } from "react-redux-guard";

export const profile = {
  mstp: state => ({
    hasProfile: selectors.hasProfile(state)
  }),
  mdtp: dispatch => ({
    fetchProfile: done => dispatch(actions.fetchProfile(done))
  }),
  guard: props => {
    if (!props.hasProfile) {
      inSuspense(props.fetchProfile);
    }
  }
};

ProfileViewer.Protected = protectAll([guards.profile]);

Doing stuff in Suspense

TODO: describe inSuspense

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago