Installations
npm install react-scoped-model-swr
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Min. Node Version
>=10
Node Version
16.8.0
NPM Version
lerna/4.0.0/node@v16.8.0+x64 (win32)
Score
66.8
Supply Chain
93.6
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
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
Contributors
Unable to fetch Contributors
Languages
TypeScript (78.08%)
Reason (11.34%)
JavaScript (10.53%)
C++ (0.05%)
Developer
LXSMNSYC
Download Statistics
Total Downloads
5,130
Last Day
1
Last Week
51
Last Month
56
Last Year
541
GitHub Statistics
23 Stars
684 Commits
3 Watching
6 Branches
1 Contributors
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
5,130
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
3
react-scoped-model-swr
Usage
Basic Usage
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
.
Props and Dependent Fetching
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);
License
MIT © lxsmnsyc
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/lxsmnsyc/scoped-model/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/lxsmnsyc/scoped-model/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/lxsmnsyc/scoped-model/main.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
32 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-3j8f-xvm3-ffx4
- Warn: Project is vulnerable to: GHSA-4p35-cfcx-8653
- Warn: Project is vulnerable to: GHSA-7f3x-x4pr-wqhj
- Warn: Project is vulnerable to: GHSA-jpp7-7chh-cf67
- Warn: Project is vulnerable to: GHSA-q6wq-5p59-983w
- Warn: Project is vulnerable to: GHSA-j9fq-vwqv-2fm2
- Warn: Project is vulnerable to: GHSA-pqw5-jmp5-px4v
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-mv48-hcvh-8jj8
- Warn: Project is vulnerable to: GHSA-353f-5xf4-qw67
- Warn: Project is vulnerable to: GHSA-c24v-8rfc-w8vw
- Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
2.5
/10
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