1.0.9 • Published 6 years ago

react-fnr v1.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

react-fnr

react-fnr is a tool for making http requests with Axios and render the result, error and more.

Installation

Using npm:

npm install react-fnr

Using yarn:

yarn add react-fnr

Testing

After installing, just run:

npm start

Or if you are using yarn:

yarn run start

navigate to http://localhost:12210 to see a test.

Importing

Requiring module:

// es6
import FNR from 'react-fnr';
// es5
const FNR = require('react-fnr');

Using HTML script tag:

<!-- Use this for production -->
<script src="https://cdn.rawgit.com/Hkh12/react-fnr/80815e49/umd/react-fnr.min.js"></script>
<!-- And this one for development -->
<script src="https://rawgit.com/Hkh12/react-fnr/master/umd/react-fnr.min.js"></script>

Example Code

import React from 'react';
import FNR from 'react-fnr';

const Example = (props) => {
    return (
        <FNR url={props.url} method='get' component={
            (data) => {
                return <p>{data}</p>
            }
        } loadingComponent={
            () => {
                return <div>Loading...</div>;
            }
        } errorComponent={
            () => {
                return <div>An error occurred. please try again later.</div>;
            }
        } />
    );
}

Reference

namedescriptiontypedefault valuerequired
urlurl to send request tostring (url)-✔️
methodrequest methodget, post, head, connect, put, patch, delete, options, traceget
componentComponent should be rendered after the server responsePropTypes.element, PropTypes.func-✔️
loadingComponentComponent should be rendered before the server response (loading message)PropTypes.element, PropTypes.func-
errorComponentComponent should be rendered if there was any error in request (if the status code us not 200)PropTypes.element, PropTypes.func-
configaxios config for request (url, method and data are overridden!)object{}

License

MIT

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago