Skip to content

Commit cb34a1f

Browse files
authored
Support React 18 (#108)
* 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
1 parent c4daa60 commit cb34a1f

10 files changed

Lines changed: 288 additions & 96 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,17 @@ mobiledoc-specific props:
343343
- `name`: The name of this card.
344344
- `onTeardown`: A callback that can be called when the rendered content is torn down.
345345

346+
### React 18 Support
347+
348+
To use custom card & atom components in React 18 without warnings, you can pass a specific ReactDOM version as a prop on the Container:
349+
350+
```js
351+
import ReactDOM from 'react-dom/client';
352+
353+
<Container ReactDOM={ReactDOM}>...</Container>;
354+
```
355+
356+
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.
346357

347358
## Development
348359

demo/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import ReactDOM from 'react-dom/client';
33
import '../node_modules/mobiledoc-kit/dist/mobiledoc.css';
44

55
import * as ReactMobiledoc from 'react-mobiledoc-editor';
@@ -46,6 +46,7 @@ const App = () => {
4646
{...config}
4747
mobiledoc={state}
4848
onChange={setState}
49+
ReactDOM={ReactDOM}
4950
>
5051
<ReactMobiledoc.Toolbar />
5152
<ImageButton />
@@ -57,4 +58,5 @@ const App = () => {
5758
);
5859
};
5960

60-
ReactDOM.render(<App />, document.getElementById('root'));
61+
const root = ReactDOM.createRoot(document.getElementById('root'));
62+
root.render(<App />);

karma.conf.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ module.exports = function (config) {
2525
resolve: {
2626
alias: {
2727
'react-mobiledoc-editor': __dirname,
28+
...(process.env.REACT_17 && {
29+
react: 'react-17',
30+
'react-dom': 'react-dom-17',
31+
'@cfaester/enzyme-adapter-react-18':
32+
'@wojtekmaj/enzyme-adapter-react-17',
33+
}),
2834
},
2935
},
3036
module: {

0 commit comments

Comments
 (0)