Skip to content

Commit 6722d06

Browse files
authored
docs(examples): react-native basic app in typescript (TanStack#3174)
* examples: react-native Same example as in the Expo snack but in Typescript * docs(examples): react-native: add link to the typescript version in the repo * fix: use proper type for onAppStateChange
1 parent 755702d commit 6722d06

28 files changed

+11788
-0
lines changed

docs/src/pages/examples/react-native.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ toc: false
55
---
66

77
- [Open the Snack](https://snack.expo.dev/@arnaudbzn/react-query-basic-example)
8+
- [TypeScript version in the repo](https://github.com/tannerlinsley/react-query/tree/master/examples/react-native)
89

910
<iframe
1011
src="https://snack.expo.dev/@arnaudbzn/react-query-basic-example"

examples/react-native/.eslintrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"root": true,
3+
"extends": "@callstack",
4+
"rules": {
5+
"react-native/no-raw-text": 0,
6+
"promise/prefer-await-to-then": 0
7+
},
8+
"settings": {
9+
"import/resolver": {
10+
"alias": {
11+
"map": [["@app", "./src"]],
12+
"extensions": [".ts", ".tsx", ".js", ".jsx", ".json"]
13+
}
14+
}
15+
}
16+
}

examples/react-native/.gitignore

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p8
6+
*.p12
7+
*.key
8+
*.mobileprovision
9+
*.orig.*
10+
web-build/
11+
coverage/
12+
13+
# macOS
14+
.DS_Store
15+
16+
.vscode/*
17+
18+
db_data
19+
20+
# @generated expo-cli sync-ba457486f18e0afcb8f6494641422f0a1150e3a9
21+
# The following patterns were generated by expo-cli
22+
23+
# OSX
24+
#
25+
.DS_Store
26+
27+
# Xcode
28+
#
29+
build/
30+
*.pbxuser
31+
!default.pbxuser
32+
*.mode1v3
33+
!default.mode1v3
34+
*.mode2v3
35+
!default.mode2v3
36+
*.perspectivev3
37+
!default.perspectivev3
38+
xcuserdata
39+
*.xccheckout
40+
*.moved-aside
41+
DerivedData
42+
*.hmap
43+
*.ipa
44+
*.xcuserstate
45+
project.xcworkspace
46+
47+
# Android/IntelliJ
48+
#
49+
build/
50+
.idea
51+
.gradle
52+
local.properties
53+
*.iml
54+
*.hprof
55+
56+
# node.js
57+
#
58+
node_modules/
59+
npm-debug.log
60+
yarn-error.log
61+
62+
# BUCK
63+
buck-out/
64+
\.buckd/
65+
*.keystore
66+
!debug.keystore
67+
68+
# fastlane
69+
#
70+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
71+
# screenshots whenever they are needed.
72+
# For more information about the recommended setup visit:
73+
# https://docs.fastlane.tools/best-practices/source-control/
74+
75+
*/fastlane/report.xml
76+
*/fastlane/Preview.html
77+
*/fastlane/screenshots
78+
79+
# Bundle artifacts
80+
*.jsbundle
81+
82+
# CocoaPods
83+
/ios/Pods/
84+
85+
# Expo
86+
.expo/*
87+
web-build/
88+
89+
# @end expo-cli

examples/react-native/.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 80,
3+
"semi": true,
4+
"singleQuote": true,
5+
"tabWidth": 2,
6+
"useTabs": false,
7+
"trailingComma": "es5"
8+
}

examples/react-native/App.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { AppStateStatus, Platform } from 'react-native';
3+
import { NavigationContainer } from '@react-navigation/native';
4+
import { QueryClient, QueryClientProvider, focusManager } from 'react-query';
5+
6+
import { useAppState } from '@app/hooks/useAppState';
7+
import { MoviesStack } from '@app/navigation/MoviesStack';
8+
import { useOnlineManager } from '@app/hooks/useOnlineManager';
9+
10+
function onAppStateChange(status: AppStateStatus) {
11+
// React Query already supports in web browser refetch on window focus by default
12+
if (Platform.OS !== 'web') {
13+
focusManager.setFocused(status === 'active');
14+
}
15+
}
16+
17+
const queryClient = new QueryClient({
18+
defaultOptions: { queries: { retry: 2 } },
19+
});
20+
21+
export default function App() {
22+
useOnlineManager();
23+
24+
useAppState(onAppStateChange);
25+
26+
return (
27+
<QueryClientProvider client={queryClient}>
28+
<NavigationContainer>
29+
<MoviesStack />
30+
</NavigationContainer>
31+
</QueryClientProvider>
32+
);
33+
}

examples/react-native/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Example
2+
3+
To run this example:
4+
5+
- Install expo CLI if needed `npm install --global expo-cli`
6+
- `yarn`
7+
- `yarn start`

examples/react-native/app.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"expo": {
3+
"name": "react-query-basic-example",
4+
"slug": "react-query-basic-example",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": [
17+
"**/*"
18+
],
19+
"ios": {
20+
"supportsTablet": true
21+
},
22+
"android": {
23+
"adaptiveIcon": {
24+
"foregroundImage": "./assets/adaptive-icon.png",
25+
"backgroundColor": "#FFFFFF"
26+
}
27+
},
28+
"web": {
29+
"favicon": "./assets/favicon.png"
30+
},
31+
"description": "React Query basic example"
32+
}
33+
}
17.1 KB
Loading
1.43 KB
Loading

examples/react-native/assets/icon.png

21.9 KB
Loading

0 commit comments

Comments
 (0)