Gathering detailed insights and metrics for rabbit-context
Gathering detailed insights and metrics for rabbit-context
npm install rabbit-context
Typescript
Module System
Node Version
NPM Version
67.6
Supply Chain
88
Quality
74.7
Maintenance
100
Vulnerability
100
License
Total Downloads
868
Last Day
1
Last Week
3
Last Month
15
Last Year
69
Minified
Minified + Gzipped
Latest Version
0.1.2
Package Id
rabbit-context@0.1.2
Unpacked Size
20.78 kB
Size
5.26 kB
File Count
7
NPM Version
6.1.0
Node Version
10.3.0
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-70%
3
Compared to previous week
Last month
0%
15
Compared to previous month
Last year
-34.3%
69
Compared to previous year
1
A framework base on React new Context API but it can avoid nesting hell.
yarn add rabbit-context
or npm i rabbit-context
1import Context from 'rabbit-context' 2 3// Everything is similar to React.Component 4class ProfileProvider extends Context.Provider { 5 constructor(props) { 6 super(props) 7 this.state = {name: 'rabbit'} 8 } 9 updateName = name => { 10 this.setState({name}) 11 } 12}
1const context = new Context(ProfileProvider) // or: const context = new Context({ProfileProvider})
1const $InjectedComponent = context.inject(AnyComponent)
1function App(props) { 2 return ( 3 <div> 4 <h1>App</h1> 5 <$InjectedComponent {...props} /> 6 </div> 7 ) 8} 9document.render( 10 <context.Provider> 11 <App msg="hello" /> 12 </context.Provider>, 13document.getElementById('root'))
Context.Provider
Context.Provider
is extends React.Component
.
So, you can do anything as same as you do in React.Component
.
But DO NOT write any lifecycle
and render
in your Context.Provider
.
new Context(Providers: Context.Provider|object, smartTransform: boolean = true)
You can construct Context.Provider
in two ways.
new Context(ProfileProvider)
new Context({ProfileProvider, ContactProvider})
smartTransform
will auto transform ProfileProvider
and ContactProvider
to profile
and contact
as {profile, contact}
in second way when passing compositedProps
to injected Components, compositedProps
is composited with values
from Provider
and the props
from parent Component, and the second one has higher priority.
context.inject(Component: React.Component): React.Component
Return a wrapped Component that you can receive values as props
from Providers.
No vulnerabilities found.
No security vulnerabilities found.