@cparram/use-api
v0.1.1
Published
React Hook to manages Api calls with redux.
Downloads
3
Readme
useApi
React Hook to manages Api calls with redux.
Getting Started
These instructions will get you a copy of this package up and running on your project.
Install dependencies
Ensure packages are installed with correct version numbers by running:
(
export PKG=@cparram/use-api;
npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g; s/ *//g' | xargs npm install --save "$PKG"
)
Which produces and runs a command like:
npm install --save @cparram/use-api react@>=#.## react-redux@>=#.## redux@>=#.##
Usage
- Connect reducer into store configuration:
import { combineReducers } from 'redux';
import { apiReducer } from '@cparram/use-api';
const appReducer = combineReducers({
api: apiReducer,
// ... other reducers.
});
- Use Hook into funcional components:
import React, { useEffect } from 'react';
import useApi from '@cparram/use-api';
const Component = props => {
const [api, apiCall] = useApi('redux-store-key')
// Call api on component mount
useEffect(() => {
apiCall({ endpoint: 'your-endpoint.com' })
}, [])
// ... rest of the component
}
CONTRIBUTING
As this project is build over node v11, the recomendation for development is docker. You can also use nvm.
Development
Installing
A step by step series of examples that tell you how to get a development env running.
docker build -t use_api .
Running the tests
Plese refer to travis config file
docker run -it -v "$PWD":/app use_api check-audit
docker run -it -v "$PWD":/app use_api npm run lint
docker run -it -v "$PWD":/app use_api npm run build
docker run -it -v "$PWD":/app use_api npm run size
Built With
- Docker - Package Software into Standardized Units for Development, Shipment and Deployment.
- React - Frontend framework.
- Redux - A predictable state container for JavaScript.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- César Parra - Initial work - @cparram
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details