Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Yoctol/async-update-props

Repository files navigation

async-update-props

Greenkeeper badge

NPM version Build Status Test coverage Dependency Status

Async props update HoC for React Component

Install

$ npm install async-update-props

Usage

import { compose } from 'redux';
import { connect } from 'react-redux';
import asyncUpdateProps from 'async-update-props';

import Page from '../components/Page';
import { fetchDataRequest } from '../actions';


const mapStateToProps = (state) => ({
  ...
});

const updater = (props) => {
  props.fetchDataRequest();
};

const shouldUpdateWhenReceiveProps = () => false;


export default compose(
  connect(mapStateToProps, {
    fetchDataRequest,
  }),
  asyncUpdateProps(updater, shouldUpdateWhenReceiveProps)
)(Page);

If updater returns a promise, setState will be called with resolved value automatically:

import asyncUpdateProps from 'async-update-props';

import Page from '../components/Page';
import * as apis from '../apis';


const updater = () => {
  return apis.fetchDataRequest();
};

const shouldUpdateWhenReceiveProps = () => false;


export default asyncUpdateProps(updater, shouldUpdateWhenReceiveProps)(Page);

API

asyncUpdateProps(updater, shouldUpdateWhenReceiveProps)

updater

Required Type: func

shouldUpdateWhenReceiveProps

Optional Type: func Default: () => true

License

MIT © Yoctol

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published