Installations
npm install react-flowstate
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
18.16.0
NPM Version
9.5.1
Score
72.6
Supply Chain
98.5
Quality
75.3
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (89.12%)
JavaScript (7.7%)
CSS (2.44%)
MDX (0.69%)
SCSS (0.05%)
Developer
Download Statistics
Total Downloads
577
Last Day
2
Last Week
11
Last Month
17
Last Year
106
GitHub Statistics
16 Stars
90 Commits
4 Forks
1 Watching
3 Branches
2 Contributors
Bundle Size
12.02 kB
Minified
4.43 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.4
Package Id
react-flowstate@1.0.4
Unpacked Size
114.04 kB
Size
23.83 kB
File Count
17
NPM Version
9.5.1
Node Version
18.16.0
Publised On
10 Aug 2023
Total Downloads
Cumulative downloads
Total Downloads
577
Last day
0%
2
Compared to previous day
Last week
450%
11
Compared to previous week
Last month
112.5%
17
Compared to previous month
Last year
-77.5%
106
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
react-flowstate
useState and useEffect, they're so lame
They're making me mad, I'm gonna change the game
react-flowstate, the library that's gonna make you feel sane
So say goodbye to those two, and let's get this party started!
This is from Google Bard. Don't like it? Send your PR!
Features
- Dead simple to use.
- Automatically manages data lifecycle and display condition.
- Reloads data on dependency change with debounce support.
- Supports React Native and TypeScript.
Install
npm install react-flowstate
Quickstart
1import {DataLayout} from 'react-flowstate'; 2 3function App() { 4 return ( 5 <DataLayout 6 dataSource={() => fetchData()} 7 loadingIndicator={() => ( 8 <div>Loading ...</div> 9 )} 10 errorFallback={(err) => ( 11 <div>{err.message}</div> 12 )} 13 > 14 {({data}) => ( 15 <div>Your data is here: {data}</div> 16 )} 17 </DataLayout> 18 ); 19}
API Reference
<DataLayout />
Component that helps you with controlling data fetching and display.
Props
initialData?: Data
- Supply this value will set initial data and skip initial loading.
children?: ReactNode | (props: DataLayoutProps) => ReactNode
- If
dataFallback
prop is not supplied,children
will act asDataFallback
- If
dataFallback
prop is supplied,children
will act as a dynamic view that allows us to dynamically render whatever we want.
dataSource: (deps?: DependencyList) => Promise
- Query function that fetches data and return a Promise.
- It is passed an optional dependency list that triggers reload behavior.
dependencies?: DependencyList
- If present, data will be reloaded if the values in the list change.
debounceDelay?: number;
- The number of milliseconds to delay invoking
dataSource
reload behavior. - If not present, any changes to
dependendcies
prop will trigger reload behavior and may affect the performance.
loadingIndicator?: RenderFunction | React.ReactNode
- Render loading UI
shadowReload?: boolean
-
Default:
false
-
If
shadowReload
is true, the reload behavior will keep current displayed data UI as-is and not showing loading indicator. However, if there is no existing data being display, loading indicator is still shown.
preserveDataOnError?: boolean
- Default:
false
- If
preserveDataOnError
isfalse
and query function failed to fetch new data, current existing data will be set to benull
anderrorFallback
will be displayed. - Set
preserveDataOnError
to betrue
preserve existing data even if the query failed. Can be use together withonError
prop to show the error message to user (e.g: usingtoarst
oralert()
).
onError?: (err: Error, state: DataLayoutState) => unknown
- Callback function invoked when
dataSource
fails to fetch data.
errorFallback?: ((err: Error, state: DataLayoutProps) => React.ReactNode) | React.ReactNode
- Render error UI
dataFallback?: DataFallbackRenderFunction | React.ReactNode
- Render data UI
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.