![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
cheap-di-react
Advanced tools
Dependency injection based on cheap-di for using in React components with React Context
Integration of cheap-di into React via React.context
There is simple logger.
logger.ts
export abstract class Logger {
abstract debug(message: string): void;
}
export class ConsoleLogger extends Logger {
constructor(private prefix: string) {
super();
}
debug(message: string) {
console.log(`${this.prefix}: ${message}`);
}
}
export class AnotherConsoleLogger extends Logger {
debug(message: string) {
console.log(message);
}
}
Use it in react
components.tsx
import {
DIProvider,
DIOneTimeProvider,
} from 'cheap-di-react';
import { Logger, ConsoleLogger } from './logger';
const RootComponent = () => {
return (
<>
<DIProvider
// will update dependencies on each render
dependencies={[
dr => dr.registerType(ConsoleLogger).as(Logger).with('my message'),
]}
// shortcut for dependencies={[ dr => dr.registerType(AnotherConsoleLogger) ]}
self={[AnotherConsoleLogger]}
>
<ComponentA/>
</DIProvider>
<DIOneTimeProvider
// will use initial dependecies (it uses useMemo under hood)
dependencies={[
dr => dr.registerType(ConsoleLogger).as(Logger).with('my message'),
]}
// will use initial self dependecies (it uses useMemo under hood)
self={[AnotherConsoleLogger]}
>
<ComponentA/>
</DIOneTimeProvider>
</>
);
};
const ComponentA = () => {
const logger = use(Logger);
logger.debug('bla-bla-bla');
return 'my layout';
};
const ComponentB = () => {
const logger = use(AnotherConsoleLogger); // because we registered it as self
logger.debug('bla-bla-bla');
return 'my layout';
};
But remember, if you want to use auto resolving your dependencies with typescript reflection, you need
"emitDecoratorMetadata": true,
in tsconfig.ts
and any class-decorator for your service-class (read more in
cheap-di
README.md)
FAQs
Dependency injection based on cheap-di for using in React components with React Context
We found that cheap-di-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.