const App = () => (
- <LoadsProvider>
<Bacon />
- </LoadsProvider>
)
This file contains hidden or 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
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( |
This file contains hidden or 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
| const customCacheProvider = { | |
| get: ..., | |
| set: ... | |
| } | |
| const Bacon = () => ( | |
| <Loads cacheKey='bacon' cacheProvider={customCacheProvider} fn={getBacon}> | |
| ... | |
| </Loads> | |
| ) |
This file contains hidden or 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
| import cacheProvider from './cache-providers/local-storage' | |
| const App = () => ( | |
| <LoadsProvider cacheProvider={cacheProvider}> | |
| <Bacon /> | |
| </LoadsProvider> | |
| ) |
This file contains hidden or 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
| const Global = typeof window !== 'undefined' ? window : global | |
| const serialize = data => JSON.stringify(data) | |
| const deserialize = stringValue => { | |
| if (!stringValue) return | |
| let value = '' | |
| try { | |
| value = JSON.parse(stringValue) |
This file contains hidden or 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
| const withLoadsProvider = WrappedComponent => props => ( | |
| <LoadsProvider> | |
| <WrappedComponent {...props}/> | |
| </LoadsProvider> | |
| ) | |
| const Router = createRoutes({ | |
| '/eggs': withLoadsProvider(Eggs), | |
| '/bacon': withLoadsProvider(Bacon) | |
| }) |
This file contains hidden or 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
| import { LoadsProvider } from 'react-loads' | |
| const Bacon = () => ( | |
| <Loads cacheKey='bacon' fn={getBacon}> | |
| ... | |
| </Loads> | |
| ) | |
| const App = () => ( | |
| <LoadsProvider> |
This file contains hidden or 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
| const getBacon = () => | |
| axios.get('https://baconipsum.com/api/?type=meat-and-filler') | |
| const Bacon = () => ( | |
| <Loads fn={getBacon}> | |
| {({ isIdle, isLoading, isSuccess, response, load }) => ( | |
| <div> | |
| <button onClick={load}> | |
| {isIdle ? 'Get some bacon' : 'Get more bacon'} | |
| </button> |