0.1.2 • Published 7 years ago

react-forml-redux v0.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

Table of Contents

Installation

yarn add react-forml-redux

Usage

Run the saga:

import { saga } from 'react-forml-redux';

// Run it.

Then there are two options:

Option 1:

In your container:

import { bindSubmitFormToPromise } from 'react-forml-redux';
import { signin } from './creators';
import { SIGNIN_SUCCESS, SIGNIN_FAILURE } from './actions';

class SigninFormContainer extends Component {
  onSubmit = ({ email, password }) => {
    const { signin: signinDispatch } = this.props;

    return signinDispatch(email, password); // It's a promise.
  }
}

const mapDispatchToProps = dispatch => ({
  signin: bindSubmitFormToPromise(signin, SIGNIN_SUCCESS, SIGNIN_FAILURE, dispatch),
});

export default connect(null, mapDispatchToProps)(withRouter(SigninFormContainer));

Option 2

In your creator:

function signin(payload) {
  type: SIGNIN_REQUEST,
  payload,
  meta: {
    successAction: SIGNIN_SUCCESS,
    failureAction: SIGNIN_FAILURE,
  },
}

Then in your container:

import { bindSubmitFormToPromise } from 'react-forml-redux';
import { signin } from './creators';

class SigninFormContainer extends Component {
  onSubmit = ({ email, password }) => {
    const { signin: signinDispatch } = this.props;

    return signinDispatch(email, password); // It's a promise.
  }
}

const mapDispatchToProps = dispatch => ({
  signin: bindSubmitFormToPromise(signin, dispatch),
});

export default connect(null, mapDispatchToProps)(withRouter(SigninFormContainer));

License

© 2017 Postform, Inc.

It is free software, and may be redistributed under the terms specified in the (license)LICENSE.