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

feat: update Notification to support React 18 #2955

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/neat-singers-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@contentful/f36-notification': minor
---

Added support for React 18 in f36-notification package
13 changes: 11 additions & 2 deletions packages/components/notification/src/Notification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global Promise */

import React from 'react';
import { render } from 'react-dom';
import {
NotificationsManager,
ShowAction,
Expand Down Expand Up @@ -35,7 +34,17 @@ function createRoot(callback: () => void) {
const container = document.createElement('div');
document.body.appendChild(container);

render(<NotificationsManager register={registerAPI} />, container, callback);
if (parseInt(React.version) >= 18) {
import("react-dom/client").then(module => {
const root = module.createRoot(container);
root.render(<NotificationsManager register={registerAPI} />);
callback()
});
} else {
import("react-dom").then(module => {
module.render(<NotificationsManager register={registerAPI} />, container, callback);
});
}
}

function afterInit<PromiseValueType>(fn: Function) {
Expand Down
Loading