Gathering detailed insights and metrics for @lxsmnsyc/react-scoped-model-swr
Gathering detailed insights and metrics for @lxsmnsyc/react-scoped-model-swr
Gathering detailed insights and metrics for @lxsmnsyc/react-scoped-model-swr
Gathering detailed insights and metrics for @lxsmnsyc/react-scoped-model-swr
npm install @lxsmnsyc/react-scoped-model-swr
Typescript
Module System
Min. Node Version
Node Version
NPM Version
64.1
Supply Chain
96.1
Quality
74.6
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
1,249
Last Day
1
Last Week
2
Last Month
2
Last Year
130
23 Stars
684 Commits
3 Watching
6 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.2.2
Package Id
@lxsmnsyc/react-scoped-model-swr@0.2.2
Unpacked Size
67.28 kB
Size
7.14 kB
File Count
16
NPM Version
lerna/3.22.1/node@v14.9.0+x64 (win32)
Node Version
14.9.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
2
Compared to previous week
Last month
-60%
2
Compared to previous month
Last year
-48.6%
130
Compared to previous year
1
2
The package exports two model factories: createSWRModel
and createSWRInfiniteModel
.
1import { createSWRModel } from '@lxsmnsyc/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 '@lxsmnsyc/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