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

Support React 18 #108

Merged
merged 7 commits into from
Aug 8, 2022
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ mobiledoc-specific props:
- `name`: The name of this card.
- `onTeardown`: A callback that can be called when the rendered content is torn down.

### React 18 Support

To use custom card & atom components in React 18 without warnings, you can pass a specific ReactDOM version as a prop on the Container:

```js
import ReactDOM from 'react-dom/client';

<Container ReactDOM={ReactDOM}>...</Container>;
```

Notice the React 18 specific import path. Internally, components will render with the new `createRoot` API if available and fallback to the legacy `render` method.

## Development

Expand Down
6 changes: 4 additions & 2 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import '../node_modules/mobiledoc-kit/dist/mobiledoc.css';

import * as ReactMobiledoc from 'react-mobiledoc-editor';
Expand Down Expand Up @@ -46,6 +46,7 @@ const App = () => {
{...config}
mobiledoc={state}
onChange={setState}
ReactDOM={ReactDOM}
>
<ReactMobiledoc.Toolbar />
<ImageButton />
Expand All @@ -57,4 +58,5 @@ const App = () => {
);
};

ReactDOM.render(<App />, document.getElementById('root'));
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
6 changes: 6 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ module.exports = function (config) {
resolve: {
alias: {
'react-mobiledoc-editor': __dirname,
...(process.env.REACT_17 && {
react: 'react-17',
'react-dom': 'react-dom-17',
'@cfaester/enzyme-adapter-react-18':
'@wojtekmaj/enzyme-adapter-react-17',
}),
},
},
module: {
Expand Down
Loading