The frontend component of PuffPastry, meant to interface with the backend, which in turn interfaces with the smart contract.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

useFetch.ts 727 B

8 meses atrás
1234567891011121314151617181920212223
  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. }