spa-api-provider
v1.0.8
Published
React Context API Provider for handling game data
Readme
API Provider
A React Context API provider for managing game data and configurations.
Installation
Install the package using npm:
npm install spa-api-providerUsage
Import and Wrap Your App
import React from 'react';
import { ApiProvider } from 'spa-api-provider';
const App = () => {
return (
// <ApiProvider apiUrl="https://api.example.com" token="your-token"> /optional
<ApiProvider>
<YourComponent />
</ApiProvider>
);
};
export default App;Using the API Context
import { useApi } from 'spa-api-provider';
const YourComponent = () => {
const { getGameScores, saveGameScore } = useApi();
const fetchScores = async () => {
const scores = await getGameScores();
console.log(scores);
};
return (
<div>
<button onClick={fetchScores}>Get Scores</button>
</div>
);
};