recoil#useRecoilValueLoadable JavaScript Examples
The following examples show how to use
recoil#useRecoilValueLoadable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DetailPage.js From app-personium-trails with Apache License 2.0 | 6 votes |
function LocationDataURLView({ __id }) {
const locationUrlLoadable = useRecoilValueLoadable(locationURLFromId(__id));
const locationUrl =
locationUrlLoadable.state === 'hasValue'
? locationUrlLoadable.contents
: null;
console.log({ locationUrl });
const isLoading = locationUrlLoadable.state === 'loading';
return (
<Segment>
<Header as="h4">Location URL</Header>
<Form loading={isLoading}>
{locationUrl ? (
<LocationDataURLViewChild __id={__id} locationUrl={locationUrl} />
) : null}
</Form>
</Segment>
);
}
Example #2
Source File: LocationPage.js From app-personium-trails with Apache License 2.0 | 6 votes |
export function LocationPage() {
const locationsLoadable = useRecoilValueLoadable(locationResults);
const setQuery = useSetRecoilState(locationQuery);
const { year, month, day } = useParams();
useEffect(() => {
// every time mounted, this make new object
setQuery({
year: Number(year),
month: Number(month),
day: Number(day),
});
}, [year, month, day]);
return (
<>
<LocationFilter year={year} month={month} day={day} />
{locationsLoadable.state === 'loading' ? (
<h1>Loading...</h1>
) : (
<Suspense fallback={<h1>loading</h1>}>
<Item.Group>
{locationsLoadable.contents.map(item => (
<LocationItem item={item} key={`location_item_${item.__id}`} />
))}
</Item.Group>
</Suspense>
)}
</>
);
}
Example #3
Source File: Statistics.js From recoil-paint with MIT License | 5 votes |
export default function Statistics({ id, series, status, ...others }) {
const setItemState = useSetRecoilState(itemWithId(id));
const statisticsLoadable = useRecoilValueLoadable(statisticsQuery(id));
useEffect(() => {
if (statisticsLoadable.state === 'hasValue') {
setItemState(item => ({
...item,
...statisticsLoadable.contents,
status: 'loaded'
}));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [statisticsLoadable.state]);
let content;
if (status === 'loading') {
content = <ActivityIndicator size="large" />
} else {
content = (
<View style={styles.container}>
{series.map((serie, i) => (
<View
key={`serie-${i}`}
style={[
styles.bar,
{
height: serie * 100,
}
]}
/>
))}
</View>
)
}
return (
<Element
{...others}
style={styles.root}
>
{content}
</Element>
);
}
Example #4
Source File: DetailPage.js From app-personium-trails with Apache License 2.0 | 5 votes |
function LocationODataView({ __id }) {
const locationInfoLoadable = useRecoilValueLoadable(
locationODataFromId(__id)
);
const isLoading = locationInfoLoadable.state === 'loading';
const locationInfo =
locationInfoLoadable.state === 'hasValue'
? locationInfoLoadable.contents
: null;
return (
<Segment>
<Header as="h4">some information about the location</Header>
{isLoading ? (
<div>Loading...</div>
) : locationInfo === null ? null : (
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Value</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{Object.entries(locationInfo).map(([key, val]) => {
if (typeof val === 'object') return null;
return (
<Table.Row key={key}>
<Table.Cell>{key}</Table.Cell>
<Table.Cell style={{ overflowWrap: 'anywhere' }}>
{val}
</Table.Cell>
</Table.Row>
);
})}
</Table.Body>
</Table>
)}
</Segment>
);
}