Skip to content

Commit 71b2800

Browse files
authored
docs/example-usage (#13)
* docs: updated readme with example usage * fix: requested changes
1 parent 2b45784 commit 71b2800

1 file changed

Lines changed: 73 additions & 21 deletions

File tree

README.md

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,109 @@
11
# @swmansion/react-native-detour
22

3-
sdk for handling deferred links
3+
SDK for handling deferred links in react native
44

55
## Installation
66

7+
npm:
8+
79
```sh
810
npm install @swmansion/react-native-detour
911
```
1012

13+
yarn:
14+
15+
```sh
16+
yarn add @swmansion/react-native-detour
17+
```
18+
19+
pnpm:
20+
21+
```sh
22+
pnpm add @swmansion/react-native-detour
23+
```
24+
25+
bun:
26+
27+
```sh
28+
bun add @swmansion/react-native-detour
29+
```
30+
1131
#### You need to install additional dependencies
1232

33+
npm:
34+
1335
```sh
1436
npm install expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application
1537
```
1638

39+
yarn:
40+
41+
```sh
42+
yarn add expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application
43+
```
44+
45+
pnpm:
46+
47+
```sh
48+
pnpm add expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application
49+
```
50+
51+
bun:
52+
53+
```sh
54+
bun add expo-localization react-native-device-info expo-clipboard @react-native-async-storage/async-storage expo-application
55+
```
56+
1757
## Usage
1858

1959
#### Initialize provider in root of your app
2060

2161
```js
2262
import { DetourProvider, type Config } from '@swmansion/react-native-detour';
2363

24-
export default function App() {
25-
const config: Config = {
26-
API_KEY: 'ssss-ssss-ssss',
27-
appID: 'app-id-from-dashboard',
28-
shouldUseClipboard: true,
29-
};
64+
const config: Config = {
65+
API_KEY: '<REPLACE_WITH_YOUR_API_KEY>',
66+
appID: '<REPLACE_WITH_APP_ID_FROM_PLATFORM>',
67+
shouldUseClipboard: true,
68+
};
69+
70+
export default function RootLayout() {
3071

3172
return(
3273
<DetourProvider config={config}>
33-
// rest of app content
74+
<RootNavigator />
3475
</DetourProvider>)
3576
}
3677
```
3778

38-
#### Use values from context
79+
#### Example usage with Expo Router
3980

4081
```js
4182
import { useDetourContext } from '@swmansion/react-native-detour';
83+
import * as SplashScreen from 'expo-splash-screen';
84+
import { Redirect, Stack } from 'expo-router';
85+
86+
SplashScreen.preventAutoHideAsync();
4287

43-
// inside component
44-
const { deferredLink, deferredLinkProcessed, route } = useDetourContext();
88+
export function RootNavigator() {
89+
const { deferredLinkProcessed, deferredLink, route } = useDetourContext();
90+
91+
useEffect(() => {
92+
if (deferredLinkProcessed) {
93+
SplashScreen.hide();
94+
}
95+
}, [deferredLinkProcessed]);
96+
97+
if (!deferredLinkProcessed) {
98+
return null;
99+
}
100+
101+
if (route) {
102+
return <Redirect href={route} />;
103+
}
104+
105+
return <Stack />;
106+
}
45107
```
46108

47109
## Types
@@ -97,16 +159,6 @@ export type DeferredLinkContext = {
97159
};
98160
```
99161

100-
## Contributing
101-
102-
- [Development workflow](CONTRIBUTING.md#development-workflow)
103-
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
104-
- [Code of conduct](CODE_OF_CONDUCT.md)
105-
106-
## License
107-
108-
MIT
109-
110162
---
111163

112164
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

0 commit comments

Comments
 (0)