Gathering detailed insights and metrics for named-context-solid
Gathering detailed insights and metrics for named-context-solid
Gathering detailed insights and metrics for named-context-solid
Gathering detailed insights and metrics for named-context-solid
npm install named-context-solid
Typescript
Module System
Node Version
NPM Version
TypeScript (77.74%)
JavaScript (22.26%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
6 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jun 30, 2024
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
Published on
Jun 30, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
2
1npm i named-context-solid
1const values = createNamedContext(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 |
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 |
defaultValue
1import { createNamedContext } from 'named-context-solid'; 2 3const { DataContext, DataProvider, useData } = createNamedContext({ 4 name: 'Data', 5 defaultValue: 0, 6});
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.