- Up dev dependencies to get rid of security vulnerabilities
- Remove examples and all excess files from the package
- Fix type of IContext from
export interface IContext {
Provider: React.ComponentType & IComponentAdditionals;
Consumer: React.ComponentType;
status?: ContextStatuses;
}
to
export interface IContext {
Provider: React.ComponentType<any> & IComponentAdditionals;
Consumer: React.ComponentType<any>;
status?: ContextStatuses;
}
- HOC
use
can acceptarray<string>
and objects besidesstring
. If you want to use the object, it should be:
export interface IContextMap {
[key: string]: Context;
}
Where Context is an object, that have two components: Provider
and Consumer
.
- HOC
use
can be used withoutAppProvider
:
const todosContext = React.createContext(['task1', 'task2']);
function MyComponent({ todos }) {
console.log(todos); // ['task1', 'task2']
return <div />;
}
const Wrapped = use({ todos: todosContext })(MyComponent);
ReactDom.render(<Wrapped />, document.qeurySelector('#app'));
- When you use array, or object with several fields in HOC
use
, the component won't render excess components. Let's compare:
use({a: AContext, b: BContext})(Component)
or use('a', 'b')(Component))
:
<Use(Component)>
<AConsumer>
<BConsumer>
<Component a={aValue} b={bValue} />
</BConsumer>
</AConsumer>
</Use(Use(Component))>
VS
use('a')(use('b')(Component))
:
<Use(Use(Component))>
<AConsumer>
<Use(Component)>
<BConsumer>
<Component a={aValue} b={bValue} />
</BConsumer>
</Use(Component)>
</AConsumer>
</Use(Use(Component))>
AppProviders
has its own display nameAppProvider
now- Added
size-limit
to project. The whole project is fewer than 2 Kb (actually 1.88 Kb). - Added new unit tests to catch cyclic dependencies, complex dependencies and working with different types (arrays, objects) in HOC
use
- Project is divided into several separate components.
- Examples now use objects in
use
section.
AppProvider
allows creating a centralized place to store your contexts- HOC
use
allows plug context to your components