The frontend component of PuffPastry, meant to interface with the backend, which in turn interfaces with the smart contract.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

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