Skip to content

Commit

Permalink
feat: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
elencho committed Jul 3, 2024
1 parent 8bd1aa9 commit 326c93c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
13 changes: 6 additions & 7 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import { multiply } from 'react-native-inactive-time';
import useInactivityListener from 'react-native-inactive-time';
import CustomText from './CustomText';

export default function App() {
const [result, setResult] = React.useState<number | undefined>();

React.useEffect(() => {
multiply(3, 7).then(setResult);
}, []);
const { elapsedTime, formattedTime } = useInactivityListener();

return (
<View style={styles.container}>
<Text>Result: {result}</Text>
<CustomText />
<Text>Elapsed Time: {elapsedTime}</Text>
<Text>Formatted Time: {formattedTime}</Text>
</View>
);
}
Expand Down
22 changes: 22 additions & 0 deletions example/src/CustomText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { View, Text } from 'react-native';
import { useEffect, useState } from 'react';
import { getElapsedTime, type ITime } from 'react-native-inactive-time';

const CustomText = () => {
const [elapsedTime, setElapsedTime] = useState<ITime>(null);
useEffect(() => {
onMount();
}, []);

const onMount = async () => {
const elapsedTime = await getElapsedTime();

Check warning on line 12 in example/src/CustomText.tsx

View workflow job for this annotation

GitHub Actions / lint

'elapsedTime' is already declared in the upper scope on line 6 column 10
setElapsedTime(elapsedTime);
};
return (
<View>

Check warning on line 16 in example/src/CustomText.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
<Text>Using UseEffect: {elapsedTime}</Text>

Check warning on line 17 in example/src/CustomText.tsx

View workflow job for this annotation

GitHub Actions / lint

'React' must be in scope when using JSX
</View>
);
};

export default CustomText;

0 comments on commit 326c93c

Please sign in to comment.