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. }