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