Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to verify Interface with Axios GET response using TypeScript

$
0
0

Data is coming back successfully from the API. This is my first time calling an API using TypeScript. The problem I am having is that I am not sure if my interface successfully verifies the API data or not.

const App = () => {  const [userData, setUserData] = useState<User[]>([])  console.log('User data: ', userData);  useEffect(() => {    axios      .get<User[]>('https://jsonplaceholder.typicode.com/users')      .then((response) => {        setUserData(response.data)      })      .catch(error => console.log(error.message))  }, [])  return ...};export default App;

Here is my interface

export interface User {  id: number,  name: string,  username: string,  email: string,  address: Address,  phone: string,  website: string,  company: Company,}export interface Address {  street: string,  suite: string,  city: string,  zipcode: string,  geo: Geolocation,}export interface Geolocation {  lat: string,  lng: string,}export interface Company {  name: string,  catchPhrase: string,  bs: string,}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>