The frontend component of PuffPastry, meant to interface with the backend, which in turn interfaces with the smart contract.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

23 行
727 B

  1. export const useFetch = () => {
  2. const ver = 'v1';
  3. const get = async <T>(endpoint: string) => {
  4. const data = await fetch(`/api/${ ver }/${ endpoint }`, {
  5. method: 'GET',
  6. mode: 'cors',
  7. headers: new Headers({ 'Content-Type': 'application/json' })
  8. });
  9. return await data.json() as T;
  10. };
  11. const post = async <T, U>(endpoint: string, payload: T) => {
  12. const data = await fetch(`/api/${ ver }/${ endpoint }`, {
  13. method: 'POST',
  14. mode: 'cors',
  15. headers: { 'Content-Type': 'application/json' },
  16. body: JSON.stringify(payload)
  17. });
  18. return await data.json() as U;
  19. };
  20. return { get, post }
  21. }