Gathering detailed insights and metrics for preact-context-provider
Gathering detailed insights and metrics for preact-context-provider
Gathering detailed insights and metrics for preact-context-provider
Gathering detailed insights and metrics for preact-context-provider
A generic <Provider /> for preact. It exposes any props you pass it into context.
npm install preact-context-provider
Typescript
Module System
Node Version
NPM Version
70.5
Supply Chain
98.3
Quality
78.9
Maintenance
100
Vulnerability
100
License
1.2.1 Explicitly support preact < X
Updated on Jul 08, 2019
2.0.0-preactx.2 Support Preact X
Updated on Jul 08, 2019
1.2.0 Add getWrappedComponent() function to provide and mergingProvide decorated components
Updated on Mar 26, 2019
1.1.1 Add <MergingProvider /> and mergingProvide()
Updated on Feb 06, 2018
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-3-Clause License
33 Stars
22 Commits
3 Forks
9 Watchers
6 Branches
7 Contributors
Updated on Apr 05, 2023
Minified
Minified + Gzipped
Latest Version
1.2.1
Package Id
preact-context-provider@1.2.1
Size
8.54 kB
NPM Version
6.4.1
Node Version
8.16.0
Published on
Jul 08, 2019
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
36
A generic <Provider />
for preact. It exposes any props you pass it into context. Also provides a merging variant <MergingProvider />
, and utility functions provide
and mergingProvide
Install it via npm:
1npm install --save preact-context-provider 2 3# or, for Preact X support 4npm install --save preact-context-provider@preactx
Then import it and use:
1import Provider from 'preact-context-provider'; 2 3let OBJ = { a: 'b' }; 4 5const App = (props, context) => { 6 // now it's exposed to context! 7 console.log(context.obj === OBJ) // true 8}; 9 10render( 11 <Provider obj={OBJ}> 12 <App /> 13 </Provider> 14);
By default, the master
branch of this repo supports preact 9 and below, and is published in normal patch/minor/major releases to the latest
tag in npm. Support for preact X (versions 10+ of preact) is handled in the preactX
branch and are always published to the preactx
tag in npm. When preact X obtains widespread adoption, the master
branch of this project will support preact X and a new major version under latest
tag will be published to in npm.
Adds all passed props
, children
into context
, making them available to all descendants.
To learn about context
, see the React Docs.
props
Object All props are exposed as properties in context
, except children1const Demo = (props, context) => { 2 console.log(context); // "{ a: 'b' }" 3}; 4render( 5 <Provider a="b"> 6 <Demo /> 7 </Provider> 8); 9// "{ a: 'b' }" 10 11// lower-level providers override higher providers for any keys that they define 12render( 13 <Provider a={key1: 'foo'} b={key2: 'bar'}> 14 <Provider a={key3: 'buz'} > 15 <Demo /> 16 </Provider> 17 </Provider> 18); 19// "{ a: { key3: 'buz' }, b: { key2: 'bar' } }"
Similar to Provider, but allows a special mergeProps
prop to allow parent supplied context keys with the same name as those
provided by the current MergingProvider
to be deep merged, instead of replaced.
To learn about context
, see the React Docs.
props
Object All props are exposed as properties in context
, except children
and mergeProps
1import Provider, { MergingProvider } from 'preact-context-provider'; 2const Demo = (props, context) => { 3 console.log(context); // "{ a: 'b' }" 4}; 5 6// with mergeProps unspecified, all parent context keys are merged with the ones presently supplied, parent values taking precedence 7render( 8 <Provider a={key1: 'foo'}> 9 <MergingProvider a={key2: 'bar'}> 10 <Demo /> 11 </MergingProvider> 12 </Provider> 13); 14// "{ a: { key1: 'foo', key2: 'bar' } }" 15 16 // when mergeProps is an array, only specified keys are merged, non-specified keys get their value from current node 17// in this example, only the 'a' context key is merged. 'b' is overwritten by the lower node 18render( 19 <Provider a={key1: 'foo'} b={key2: 'bar'}> 20 <MergingProvider mergeProps={['a']} a={key3: 'baz'} b={key4: 'buz'}> 21 <Demo /> 22 </MergingProvider> 23 </Provider> 24); 25// "{ a: { key1: 'foo', key3: 'baz' }, b: {key4: 'buz'} }"
Higher Order Component that wraps components in a Provider for the given context.
1import {provide} from 'preact-context-provider'; 2const Demo = (props, context) => { 3 console.log(context.a); // "b" 4}; 5const ProvidedDemo = provide({a: "b"})(Demo); 6 7ProvidedDemo.getWrappedComponent() === Demo; // true 8 9render( <ProvidedDemo /> );
Returns Function A function that, given a Child component, wraps it in a Provider component for the given context.
Higher Order Component that wraps components in a MergingProvider for the given context.
ctx
Object Properties to pass into context (passed to MergingProvider)1import {mergingProvide} from 'preact-context-provider'; 2const Demo = (props, context) => { 3 console.log(context.a); 4}; 5const ProvidedDemo = mergingProvide({a: "b"})(Demo); 6 7ProvidedDemo.getWrappedComponent() === Demo; // true 8 9render( <ProvidedDemo /> ); // "b"
Returns Function A function that, given a Child component, wraps it in a MergingProvider component for the given context.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 3/14 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-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