Wpis z mikrobloga

Jak zasilić sprytnie interfejs w tsx RESTem tak by nie wypisywać każdego argumentu osobno?

np.:

export interface MyInterface {
a: string;
b: string;
...
z: string;
}

---

const [myInterface, setMyInterface] = useState();

getData().then((response) => {
setMyInterface({
a: response.a,
b: repsonse.b,
...
z: response.z
})
})

#javascript #typescript
  • 5
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach

@programista4k:
Jak masz taką samą strukture jak interfejs to mozesz po prostu to przekazać.

const [myInterface, setMyInterface] = useState();

getData().then((response: MyInterface)
  • Odpowiedz