@@ -64,11 +64,18 @@ Storybook's webpack configuration will require adjustments to allow you to trans
64
64
In your Storybook configuration file (i.e., ` .storybook/main.js ` ) add the following:
65
65
66
66
``` js:title=.storybook/main.js
67
+ const React = require (" react" );
68
+
67
69
module .exports = {
68
70
webpackFinal: async config => {
69
71
// Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
70
72
config .module .rules [0 ].exclude = [/ node_modules\/ (?!(gatsby| gatsby-script)\/ )/ ]
71
73
74
+ // Use correct react-dom depending on React version.
75
+ if (parseInt (React .version ) <= 18 ) {
76
+ config .externals = [" react-dom/client" ];
77
+ }
78
+
72
79
// Remove core-js to prevent issues with Storybook
73
80
config .module .rules [0 ].exclude = [/ core-js/ ]
74
81
// Use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook
@@ -85,6 +92,8 @@ module.exports = {
85
92
The final ` .storybook/main.js ` should look something like this:
86
93
87
94
``` js:title=.storybook/main.js
95
+ const React = require (" react" );
96
+
88
97
module .exports = {
89
98
// You will want to change this to wherever your Stories will live
90
99
stories: [" ../src/**/*.stories.mdx" , " ../src/**/*.stories.@(js|jsx|ts|tsx)" ],
@@ -98,6 +107,11 @@ module.exports = {
98
107
// Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
99
108
config .module .rules [0 ].exclude = [/ node_modules\/ (?!(gatsby| gatsby-script)\/ )/ ]
100
109
110
+ // Use correct react-dom depending on React version.
111
+ if (parseInt (React .version ) <= 18 ) {
112
+ config .externals = [" react-dom/client" ];
113
+ }
114
+
101
115
// Remove core-js to prevent issues with Storybook
102
116
config .module .rules [0 ].exclude = [/ core-js/ ]
103
117
// Use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook
0 commit comments