Skip to content

Instantly share code, notes, and snippets.

@shinkathe
Created September 27, 2022 16:22
Show Gist options
  • Save shinkathe/e35e5125be01f1499fd522121aaa0489 to your computer and use it in GitHub Desktop.
Save shinkathe/e35e5125be01f1499fd522121aaa0489 to your computer and use it in GitHub Desktop.
Sample usage of useclient
export const MovieList = ({listId}: {listId: string}) => {
const [moviesList, setMoviesList] = useState<Movie[]>();
const { loading: loadingMovies } = useFetch<Movie[], unknown>(
request(`api/movies/${listId}`),
[listId],
{
when: () => listId != undefined,
onSuccessEffect: setMoviesList
}
return <div>
{moviesList?.map(movie => ...)}
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment