This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
react-rest-request/examples/movies/src/app.tsx

25 lines
591 B
TypeScript
Raw Normal View History

2020-11-04 14:39:57 +03:00
import React from 'react';
import { useRequest } from 'react-rest-request';
import { MoviesEndpoint, MoviesResponse } from './endpoint';
export default function App() {
const [movies, { data, loading }] = useRequest<MoviesResponse>(MoviesEndpoint);
React.useEffect(
() => {
movies();
},
[movies]
);
return !data ? (
<div>{ loading ? 'Loading...' : 'Something went wrong' }</div>
) : (
<ul>
{data.map(movie => (
<li key={movie.id}>{movie.title}</li>
))}
</ul>
);
}