Installations
npm install preact-context-provider
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.16.0
NPM Version
6.4.1
Score
70
Supply Chain
98.3
Quality
78.9
Maintenance
100
Vulnerability
100
License
Releases
1.2.1 Explicitly support preact < X
Published on 08 Jul 2019
2.0.0-preactx.2 Support Preact X
Published on 08 Jul 2019
1.2.0 Add getWrappedComponent() function to provide and mergingProvide decorated components
Published on 26 Mar 2019
1.1.1 Add <MergingProvider /> and mergingProvide()
Published on 06 Feb 2018
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
synacor
Download Statistics
Total Downloads
105,551
Last Day
7
Last Week
33
Last Month
164
Last Year
3,640
GitHub Statistics
33 Stars
22 Commits
3 Forks
10 Watching
6 Branches
7 Contributors
Bundle Size
1.40 kB
Minified
566.00 B
Minified + Gzipped
Package Meta Information
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
Publised On
08 Jul 2019
Total Downloads
Cumulative downloads
Total Downloads
105,551
Last day
-50%
7
Compared to previous day
Last week
-26.7%
33
Compared to previous week
Last month
16.3%
164
Compared to previous month
Last year
-14.6%
3,640
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
36
preact-context-provider
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
Usage
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);
Preact Version Support
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.
API
Table of Contents
Provider
Adds all passed props
, children
into context
, making them available to all descendants.
To learn about context
, see the React Docs.
Parameters
props
Object All props are exposed as properties incontext
, except children
Examples
1const 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' } }"
MergingProvider
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.
Parameters
props
Object All props are exposed as properties incontext
, exceptchildren
andmergeProps
Examples
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'} }"
provide
Higher Order Component that wraps components in a Provider for the given context.
Parameters
Examples
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.
mergingProvide
Higher Order Component that wraps components in a MergingProvider for the given context.
Parameters
ctx
Object Properties to pass into context (passed to MergingProvider)
Examples
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
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: BSD 3-Clause "New" or "Revised" License: LICENSE:0
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
- 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
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
3.8
/10
Last Scanned on 2024-12-16
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