Skip to content

Commit 56e3ba7

Browse files
authored
docs(examples): react-native: update .gitignore to exclude lib folder (TanStack#3196)
1 parent 6722d06 commit 56e3ba7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

examples/react-native/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ buck-out/
8787
web-build/
8888

8989
# @end expo-cli
90+
91+
!lib

examples/react-native/src/lib/api.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import movies from '../data/movies.json';
2+
3+
export type Movie = {
4+
title: string;
5+
year: number;
6+
};
7+
8+
export type MovieDetails = Movie & {
9+
info: {
10+
plot: string;
11+
actors: string[];
12+
};
13+
};
14+
15+
function delay(t: number, v: () => void) {
16+
return new Promise(function (resolve) {
17+
setTimeout(resolve.bind(null, v), t);
18+
});
19+
}
20+
21+
export async function fetchMovies() {
22+
console.log('fetchMovies');
23+
return delay(200 + Math.floor(Math.random() * 2000), () =>
24+
movies
25+
.slice(0, 100)
26+
.map((movie) => ({ title: movie.title, year: movie.year }))
27+
) as Promise<Movie[]>;
28+
}
29+
30+
export async function fetchMovie(title: string) {
31+
console.log('fetchMovie', title);
32+
return delay(200 + Math.floor(Math.random() * 2000), () => {
33+
const result = movies.filter((item) => item.title === title);
34+
if (result.length == 0) {
35+
throw new Error('Movie not found');
36+
}
37+
return result[0];
38+
}) as Promise<MovieDetails>;
39+
}

0 commit comments

Comments
 (0)