The frontend component of PuffPastry, meant to interface with the backend, which in turn interfaces with the smart contract.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

23 satır
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. }