react-native-api-context
v1.2.2
Published
An react native context to manage all api calls in one place
Downloads
3
Maintainers
Readme
react-native-api-context
An react native context to manage all api calls in one place
Installation
npm install react-native-api-context
yarn add react-native-api-context
Usage
// inside root App.tsx
import { APIContextProvider } from 'react-native-api-context';
import Page from './Page';
export default function App() {
const BASE_URL = 'https://jsonplaceholder.typicode.com'
return (
<APIContextProvider BaseURL={BASE_URL}>
<Page/>
</APIContextProvider>
);
}
// inside any child component of APIContextProvider
import { APIContext } from 'react-native-api-context';
export default function Page() {
const { Get } = React.useContext(APIContext)
useEffect(() => {
Get({
path: 'posts'
})
.then(resp => {
console.log('[APIContext resp]:', resp)
})
.catch(err => {
console.log('[APIContext error]:', err)
})
}, []);
return (
...
);
}
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library