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
Contextual state management for React, ReasonReact and Preact
npm install react-scoped-model-swr
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.4
Supply Chain
93.6
Quality
75.9
Maintenance
100
Vulnerability
100
License
v2.0.0
Updated on Apr 04, 2021
graph-state@0.5.0
Updated on Nov 03, 2020
swr-graph-state@0.5.0
Updated on Nov 03, 2020
swr-graph-state@0.4.0
Updated on Oct 23, 2020
graph-state@0.2.0
Updated on Oct 13, 2020
preact-scoped-model@0.3.0
Updated on Oct 09, 2020
TypeScript (78.08%)
Reason (11.34%)
JavaScript (10.53%)
C++ (0.05%)
Total Downloads
5,548
Last Day
1
Last Week
37
Last Month
73
Last Year
766
MIT License
23 Stars
684 Commits
2 Watchers
6 Branches
1 Contributors
Updated on Jun 05, 2022
Minified
Minified + Gzipped
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
1,750%
37
Compared to previous week
Last Month
-67.1%
73
Compared to previous month
Last Year
45.1%
766
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
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
45 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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