mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-07-20 18:51:53 +00:00
Explicitly wrap in ContainerProvider when calling renderWithStore
This commit is contained in:
@@ -30,8 +30,11 @@ export const useDependencies = <T extends unknown[]>(...names: string[]): T => {
|
||||
}) as T;
|
||||
};
|
||||
|
||||
type Optionalize<P, K extends keyof P> = Omit<P, K> & Partial<Pick<P, K>>;
|
||||
|
||||
/**
|
||||
* Higher Order Component used to inject services into components as props.
|
||||
* All dependencies become optional props so that they can still be explicitly set in tests if desired.
|
||||
*/
|
||||
export function withDependencies<
|
||||
Props extends Record<string, unknown>,
|
||||
@@ -39,16 +42,16 @@ export function withDependencies<
|
||||
>(
|
||||
Component: ComponentType<Props>,
|
||||
dependencyNames: DependencyName[],
|
||||
): ComponentType<Omit<Props, DependencyName>> {
|
||||
): ComponentType<Optionalize<Props, DependencyName>> {
|
||||
function Wrapper(props: Omit<Props, DependencyName>) {
|
||||
const container = useContainer('withDependencies');
|
||||
const container = useContext(ContainerContext);
|
||||
|
||||
// Inject services, unless they have been overridden by props passed from
|
||||
// the parent component.
|
||||
const dependencies: Partial<Record<DependencyName, unknown>> = {};
|
||||
for (const dependency of dependencyNames) {
|
||||
if (!(dependency in props)) {
|
||||
dependencies[dependency] = container[dependency];
|
||||
dependencies[dependency] = container?.[dependency];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user