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

Allow custom renderer to receive function or react node #291

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ const ModalizeBase = (
);
};

const renderElement = (Element: React.ReactNode): JSX.Element =>
typeof Element === 'function' ? Element() : Element;

const renderComponent = (
component: React.ReactNode,
name: 'header' | 'footer' | 'floating',
Expand All @@ -680,8 +683,6 @@ const ModalizeBase = (
return null;
}

const renderElement = (Element: React.ReactNode): JSX.Element =>
typeof Element === 'function' ? Element() : Element;
const tag = renderElement(component);

/**
Expand Down Expand Up @@ -757,7 +758,8 @@ const ModalizeBase = (
}

if (customRenderer) {
return React.cloneElement(customRenderer, { ...opts });
const tag = renderElement(customRenderer);
return React.cloneElement(tag, { ...opts });
}

return (
Expand Down