Skip to content

Commit

Permalink
Support React 18 (#108)
Browse files Browse the repository at this point in the history
* Support React 18

* adapter

* Run tests in react 17 & 18

* Update the API - conditional imports are messy

* Revert prettier on README

* simplify api

* v0.14.0
  • Loading branch information
gpoitch authored Aug 8, 2022
1 parent c4daa60 commit cb34a1f
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 96 deletions.
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

0 comments on commit cb34a1f

Please sign in to comment.