Gathering detailed insights and metrics for react-scoped-model-swr
Gathering detailed insights and metrics for react-scoped-model-swr
Gathering detailed insights and metrics for react-scoped-model-swr
Gathering detailed insights and metrics for react-scoped-model-swr
npm install react-scoped-model-swr
Typescript
Module System
Min. Node Version
Node Version
NPM Version
66.8
Supply Chain
93.6
Quality
75.9
Maintenance
100
Vulnerability
100
License
v2.0.0
Published on 04 Apr 2021
graph-state@0.5.0
Published on 03 Nov 2020
swr-graph-state@0.5.0
Published on 03 Nov 2020
swr-graph-state@0.4.0
Published on 23 Oct 2020
graph-state@0.2.0
Published on 13 Oct 2020
preact-scoped-model@0.3.0
Published on 09 Oct 2020
TypeScript (78.08%)
Reason (11.34%)
JavaScript (10.53%)
C++ (0.05%)
Total Downloads
5,130
Last Day
1
Last Week
51
Last Month
56
Last Year
541
23 Stars
684 Commits
3 Watching
6 Branches
1 Contributors
Latest Version
3.0.1
Package Id
react-scoped-model-swr@3.0.1
Unpacked Size
64.30 kB
Size
7.81 kB
File Count
18
NPM Version
lerna/4.0.0/node@v16.8.0+x64 (win32)
Node Version
16.8.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
5,000%
51
Compared to previous week
Last month
330.8%
56
Compared to previous month
Last year
-21.5%
541
Compared to previous year
3
The package exports two model factories: createSWRModel
and createSWRInfiniteModel
.
1import { createSWRModel } from 'react-scoped-model';
The simplest form of an SWR Model can be created using just a key value.
1const TopItems = createSWRModel('/api/items/top');
which can be mounted like a scoped model instance:
1<TopItems.Provider> 2 <TopItemsList /> 3</TopItems.Provider>
And can be used with hooks:
1import { useSelector } from 'react-scoped-model'; 2 3// ... 4const data = useSelector(TopItems, (state) => state.data);
All SWR and SWR Infinite models are also subject to the <SWRConfig>
setup.
The second parameter for createSWRModel
is reserved for custom fetching, but it is required to be returned by a higher-order function:
1const TopItems = createSWRModel('/api/items/top', () => getTopItems);
The third parameter is an optional parameter and is for the SWR Config.
1const TopItems = createSWRModel('/api/items/top', () => getTopItems, { 2 initialData: [], 3});
The fourth parameter is an optional parameter reserved for the scoped model options e.g. displayName
.
SWR and SWR Infinite models can also receive props, and can be used to produce dynamic key, fetcher and config, which can cause dependent or conditional fetching;
1const UserDetails = createSWRModel( 2 ({ userId }) => `/api/user/${userId}`, 3 ({ userId }) => () => getUser(userId), 4); 5 6// ... 7<UserDetails.Provider userId={userId}> 8 <UserProfile /> 9</UserDetails.Provider>
You may also use hooks inside these functions as they behave as hooks:
1const RecentActivity = createSWRModel( 2 () => { 3 // Get the current sign-in token 4 const token = useAuthToken(); 5 6 // Only fetch if a token exists, 7 // signifying the signed-in user's presence 8 if (token) { 9 return ['/api/recent-activity', token]; 10 } 11 return null, 12 }, 13 () => getRecentActivity, 14);
MIT © lxsmnsyc
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
32 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More