cheap-di-react
Advanced tools
Comparing version 1.0.6 to 1.1.0
{ | ||
"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` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22533
144