Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The useAsyncData() method does not establish the data type explicitly. It dynamically infers the data type based on the data returned from the API call. However, you can provide TypeScript interfaces or types for the returned data to enforce type safety and help with the data type inference. This can be done by passing the interface or type as a generic parameter to the useAsyncData() method, like this:

interface UserData {
  id: number;
  name: string;
  email: string;
}

const { data } = useAsyncData<UserData>('/api/user');

In this example, the useAsyncData() method expects the API response to be of type UserData, and the returned data will have the same shape and properties as the interface.