Skip to content

Commit 8c9d0dc

Browse files
committed
Add React Native (Expo) example.
1 parent a28daa2 commit 8c9d0dc

File tree

9 files changed

+8093
-0
lines changed

9 files changed

+8093
-0
lines changed

examples/with-react-native/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p12
6+
*.key
7+
*.mobileprovision
8+
*.orig.*
9+
web-build/
10+
web-report/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

examples/with-react-native/App.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react"
2+
import Async from "react-async"
3+
import { StyleSheet, Text, View, Image } from "react-native"
4+
5+
const loadUser = ({ userId }) =>
6+
fetch(`https://reqres.in/api/users/${userId}`)
7+
.then(res => (res.ok ? res : Promise.reject(res)))
8+
.then(res => res.json())
9+
.then(json => json.data)
10+
11+
export default function App() {
12+
return (
13+
<View style={styles.container}>
14+
<Async promiseFn={loadUser} userId={1}>
15+
<Async.Pending>
16+
<Text>Loading...</Text>
17+
</Async.Pending>
18+
<Async.Fulfilled>
19+
{user => (
20+
<>
21+
<Image
22+
style={{ width: 100, height: 100, marginBottom: 10 }}
23+
source={{ uri: user.avatar }}
24+
/>
25+
<Text style={{ fontSize: 16 }}>
26+
{user.first_name} {user.last_name}
27+
</Text>
28+
</>
29+
)}
30+
</Async.Fulfilled>
31+
<Async.Rejected>{res => <Text>{res.status}</Text>}</Async.Rejected>
32+
</Async>
33+
</View>
34+
)
35+
}
36+
37+
const styles = StyleSheet.create({
38+
container: {
39+
flex: 1,
40+
backgroundColor: "#fff",
41+
alignItems: "center",
42+
justifyContent: "center",
43+
},
44+
})

examples/with-react-native/app.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "React Async example",
4+
"slug": "with-react-native",
5+
"privacy": "public",
6+
"sdkVersion": "33.0.0",
7+
"platforms": [
8+
"ios",
9+
"android",
10+
"web"
11+
],
12+
"version": "1.0.0",
13+
"orientation": "portrait",
14+
"icon": "./assets/icon.png",
15+
"splash": {
16+
"image": "./assets/splash.png",
17+
"resizeMode": "contain",
18+
"backgroundColor": "#ffffff"
19+
},
20+
"updates": {
21+
"fallbackToCacheTimeout": 0
22+
},
23+
"assetBundlePatterns": [
24+
"**/*"
25+
],
26+
"ios": {
27+
"supportsTablet": true
28+
}
29+
}
30+
}
1.07 KB
Loading
7.01 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

0 commit comments

Comments
 (0)