Skip to content

Commit

Permalink
fix how custom content is wrapped. fixes #5586
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Jul 28, 2020
1 parent 44a00b1 commit 1c67145
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages-premium
27 changes: 19 additions & 8 deletions packages/common/src/common/render-hook.tsx
Expand Up @@ -79,6 +79,7 @@ export type DefaultContentGenerator<HookProps> = (hookProps: HookProps) => Compo
// for forcing rerender of components that use the ContentHook
export const CustomContentRenderContext = createContext<number>(0)


export interface ContentHookProps<HookProps> {
hookProps: HookProps
content: CustomContentGenerator<HookProps>
Expand All @@ -90,7 +91,23 @@ export interface ContentHookProps<HookProps> {
backupElRef?: RefObject<any>
}

export class ContentHook<HookProps> extends BaseComponent<ContentHookProps<HookProps>> { // TODO: rename to CustomContentHook?
interface ContentHookInnerProps<HookProps> extends ContentHookProps<HookProps> {
renderId: number
}


export function ContentHook<HookProps>(props: ContentHookProps<HookProps>) { // TODO: rename to CustomContentHook?
return (
<CustomContentRenderContext.Consumer>
{(renderId) => (
<ContentHookInner renderId={renderId} {...props} />
)}
</CustomContentRenderContext.Consumer>
)
}


class ContentHookInner<HookProps> extends BaseComponent<ContentHookInnerProps<HookProps>> {

private innerElRef = createRef()
private customContentInfo: {
Expand All @@ -101,13 +118,7 @@ export class ContentHook<HookProps> extends BaseComponent<ContentHookProps<HookP


render() {
return (
<CustomContentRenderContext.Consumer>
{() => (
this.props.children(this.innerElRef, this.renderInnerContent())
)}
</CustomContentRenderContext.Consumer>
)
return this.props.children(this.innerElRef, this.renderInnerContent())
}


Expand Down

0 comments on commit 1c67145

Please sign in to comment.