Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cheap-di-react

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheap-di-react - npm Package Compare versions

Comparing version 1.0.6 to 1.1.0

2

package.json
{
"name": "cheap-di-react",
"version": "1.0.6",
"version": "1.1.0",
"description": "",

@@ -5,0 +5,0 @@ "scripts": {

@@ -96,2 +96,49 @@ # cheap-di-react

If you want to use React.Context dependency (with refreshing dependency consumers),
for `@singleton` service, you should add SingletonStateProvider under your dependency Provider
```tsx
import { SelfOneTimeProvider, SingletonStateProvider, use } from 'cheap-di-react';
import { singleton } from 'cheap-di/dist/singleton';
@singleton()
class Consumer {
data: string[] = ['initial'];
async loadData() {
this.data = await Promise.resolve(['some']);
}
}
const RootComponent = () => {
return (
<SelfOneTimeProvider dependencies={[Consumer]}>
<SingletonStateProvider>
<ComponentB/>
</SingletonStateProvider>
</SelfOneTimeProvider>
);
};
const ComponentB = () => {
const consumer = use(Consumer);
useEffect(() => {
(async () => {
await consumer.loadData();
})();
}, []);
return (
<div>
{consumer.data.map(text => (
<span key={text} style={{ color: 'blue' }}>
{text}
</span>
))}
</div>
);
};
```
You can see more examples in `cheap-di-react/src/poc/components.tsx`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc