1.2.2 • Published 1 year ago

react-native-api-context v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.0

1 year ago