Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes withSitecoreContext typescript definition #347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { SitecoreContext, SitecoreContextFactory } from './SitecoreContext';
import { ComponentFactory } from './sharedTypes';
import { withSitecoreContext, ComponentConsumerProps } from '../enhancers/withSitecoreContext'

const NestedComponent: FC<ComponentConsumerProps> = (props: ComponentConsumerProps) => <div>{props.sitecoreContext && 'test'}</div>;
const NestedComponentWithContext: FC = withSitecoreContext()(NestedComponent);
interface NestedComponentProps extends ComponentConsumerProps {
anotherProperty?: string,
}
const NestedComponent: FC<NestedComponentProps> = (props: NestedComponentProps) => <div>{props.sitecoreContext && 'test'}</div>;
const NestedComponentWithContext = withSitecoreContext()(NestedComponent);

const components = new Map();
const mockComponentFactory: ComponentFactory = name => components.get(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ export type WithSitecoreContextHocProps<ComponentProps> = Pick<ComponentProps, E

export function withSitecoreContext(options?: WithSitecoreContextOptions) {

return function withSitecoreContextHoc<ComponentProps extends ComponentConsumerProps>(Component: React.ComponentType<ComponentConsumerProps>) {
return function withSitecoreContextHoc<ComponentProps extends ComponentConsumerProps>(Component: React.ComponentType<ComponentProps>) {

return function WithSitecoreContext(props: WithSitecoreContextHocProps<ComponentProps>) {

return (
<SitecoreContextReactContext.Consumer>
{context => <Component {...props}
{context => <Component {...props as ComponentProps}
sitecoreContext={context.context}
updateSitecoreContext={options && options.updatable && context.setSitecoreContext} />}
</SitecoreContextReactContext.Consumer>
);
};


};
}