Installations
npm install named-context-solid
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.15.0
NPM Version
10.7.0
Score
66.1
Supply Chain
98.4
Quality
76.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (77.74%)
JavaScript (22.26%)
Developer
klaseca
Download Statistics
Total Downloads
245
Last Day
1
Last Week
1
Last Month
3
Last Year
125
GitHub Statistics
6 Commits
1 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
1.0.1
Package Id
named-context-solid@1.0.1
Unpacked Size
8.80 kB
Size
2.19 kB
File Count
6
NPM Version
10.7.0
Node Version
20.15.0
Publised On
30 Jun 2024
Total Downloads
Cumulative downloads
Total Downloads
245
Last day
0%
1
Compared to previous day
Last week
0%
1
Compared to previous week
Last month
0%
3
Compared to previous month
Last year
4.2%
125
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
2
Solid
Installation
1npm i named-context-solid
API
1const values = createNamedContext(params);
params
Property | Default value | Description |
---|---|---|
name | - | Name of your context. Use as prefix or postfix in returned values |
defaultValue | - | Default value of your context |
isNullishAllowed | false | Property that allows the use of nullish values in context |
values
Property | Description |
---|---|
${params.name}Context | Context component from createContext from solid-js |
${params.name}Provider | Context.Provider component. Alias for ${params.name}Context.Provider |
use${params.name} | Hook to work with data from ${params.name}Context |
Usage
Create context with defined defaultValue
1import { createNamedContext } from 'named-context-solid'; 2 3const { DataContext, DataProvider, useData } = createNamedContext({ 4 name: 'Data', 5 defaultValue: 0, 6});
Create context without defined defaultValue
If you do not want to pass defaultValue
when creating a context, use helper function valueType
to specify type of value you expect
1import { createNamedContext, valueType } from 'named-context-solid'; 2 3const { DataContext, DataProvider, useData } = createNamedContext( 4 { name: 'Data', defaultValue: valueType<number>() } 5); 6 7// ... 8 9<DataContext.Provider value={1} /> 10// or 11<DataProvider value={1} /> 12/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13 `value` prop expects a value of type `number` (as specified in `valueType` function) 14*/ 15 16// ... 17 18const data = useData(); 19/* ^^^^^^^^^^^^^^^^^^^^ 20 `data` is of type `number` (as specified in `valueType` function) 21 If `useData` is used outside `DataContext.Provider` or `DataProvider` or if `value` prop is not passed, an error will be throw 22*/
If undefined
or null
value should be allowed, set isNullishAllowed
param to true
1import { createNamedContext, valueType } from 'named-context-solid'; 2 3const { NullishContext, NullishProvider, useNullish } = createNamedContext( 4 { name: 'Nullish', defaultValue: valueType<string>(), isNullishAllowed: true } 5); 6 7// ... 8 9<NullishContext.Provider value={undefined} /> 10// or 11<NullishProvider value={''} /> 12/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 13 `value` prop expects a value of type `string` (as specified in `valueType` function) or `undefined` (because `isNullishAllowed` is `true`) 14*/ 15 16// ... 17 18const data = useNullish(); 19/* ^^^^^^^^^^^^^^^^^^^^^^^ 20 `data` is of type `string` (as specified in `valueType` function) or `undefined` (because `isNullishAllowed` is `true`) 21*/
No vulnerabilities found.
No security vulnerabilities found.