npm.io
1.9.1 • Published 5 years ago

@chief-noob/restaurant-ts-sdk

Licence
MIT
Version
1.9.1
Deps
5
Size
179 kB
Vulns
0
Weekly
0

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>
  );
}