@chief-noob/restaurant-ts-sdk
v1.9.1
Published
## Introduction
Downloads
67
Readme
Restaurant API SDK for Typescript
Introduction
點菜通系統 API 串接套件,用於 Typescript 前端開發。
Usage
Create a useAPI
hook in project, inject the API_URL
and session
.
// hooks/useAPI.ts
import useSession from './useSession';
import API_URL from '../config';
import useRestaurantAPI from '@chief-noob/restaurant-ts-sdk';
function useAPI() {
const session = useSession();
return useRestaurantAPI(API_URL, session);
}
export default useAPI;
In component, simply use this hook to access the API service.
function RestaurantScreen() {
const API = useAPI();
const [restaurant, setRestaurant] = useState<Restaurant>();
useEffect(() => {
refresh();
}, []);
async function refresh() {
const l = await API.restaurant.getOne(restaurantID);
setRestaurant(l);
}
return (
<View>
...
</View>
);
}