-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use selector function to make fetch request for second model and subs…
…cribe to this selector with useRecoilValue and wrap rendered component with suspense for asynch loading
- Loading branch information
Showing
6 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
import React from 'react'; | ||
import { VStack, Center, Text, Box, Button, Dimensions, useColorModeValue, Pressable} from "native-base"; | ||
import React, { ErrorBoundary } from 'react'; | ||
import { VStack, Center, Text, Box, Button, Dimensions, useColorModeValue, Pressable, Input} from "native-base"; | ||
import { SceneMap } from 'react-native-tab-view'; | ||
import { atom, selector, useRecoilState, useRecoilValue } from 'recoil'; | ||
import l from '../../helpers/consolelog'; | ||
import { DetailsWithSuspense } from '../functions/selectors/DetailsWithSuspense'; | ||
// import { todoListState } from '../atoms/todoListState'; | ||
// import TodoItemCreator from '../atoms/TodoItemCreator'; | ||
|
||
const TabRouteSecond = () => ( | ||
<Center flex={1}> | ||
This is Tab 2 | ||
</Center> | ||
); | ||
|
||
export default TabRouteSecond; | ||
export default function TabRouteSecond() { | ||
|
||
|
||
|
||
|
||
return( | ||
<Center> | ||
<Text>Second </Text> | ||
<React.Suspense fallback={<Text>Loading...</Text>}> | ||
<DetailsWithSuspense /> | ||
</React.Suspense> | ||
</Center> | ||
) | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { selector, useRecoilValue } from 'recoil'; | ||
import { Text } from 'native-base'; | ||
import l from '../../../helpers/consolelog'; | ||
|
||
// makeing erquests | ||
// const url ="https://catfact.ninja/fact" | ||
const momentsURL = 'http://localhost:3000/api/alerts/'; | ||
|
||
// Selector that fetches data | ||
const fetchAlertnessDetails = selector({ | ||
key: 'userDetailsSelector', | ||
get: async ({ get }) => { | ||
try { | ||
const response = await fetch(momentsURL); | ||
|
||
|
||
|
||
const data = await response.json(); | ||
return data; | ||
}catch(error){ | ||
throw error; | ||
} | ||
} | ||
}); | ||
|
||
// subscribe to the selector | ||
// Data returned from Select is READ-ONLY | ||
export const DetailsWithSuspense = () => { | ||
// subscribing to the Selector | ||
const userDetails = useRecoilValue(fetchAlertnessDetails); | ||
const data = userDetails; | ||
l("Subscribed data from Selector: ", data); | ||
return ( | ||
<Text>Level: </Text> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters