Skip to content

Commit 0212e82

Browse files
Merge pull request #100 from bvaughn/feat/react-18-basic-support
feat: provide basic support of React 18
2 parents e633f20 + 38119bc commit 0212e82

File tree

7 files changed

+75
-64
lines changed

7 files changed

+75
-64
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"transform": "react-transform-hmr",
1010
"imports": ["react"],
1111
"locals": ["module"]
12-
}, {
13-
"transform": "react-transform-catch-errors",
14-
"imports": ["react", "redbox-react"]
1512
}]
1613
}
1714
}

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ To use it, just provide it with an array of search terms and a body of text to h
1212

1313
```jsx
1414
import React from "react";
15-
import ReactDOM from "react-dom";
15+
import { createRoot } from "react-dom/client";
1616
import Highlighter from "react-highlight-words";
1717

18-
ReactDOM.render(
18+
19+
const root = createRoot(document.getElementById("root"));
20+
root.render(
1921
<Highlighter
2022
highlightClassName="YourHighlightClass"
2123
searchWords={["and", "or", "the"]}
2224
autoEscape={true}
2325
textToHighlight="The dog is chasing the cat. Or perhaps they're just playing?"
24-
/>,
25-
document.getElementById("root")
26+
/>
2627
);
2728
```
2829

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ module.exports = function (config) {
1919
require('karma-sourcemap-loader'),
2020
require('karma-phantomjs2-launcher')
2121
],
22-
webpack: require('./webpack.config.dev')
22+
webpack: require('./webpack.config.test')
2323
})
2424
}

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"lint": "standard",
1515
"prebuild": "npm run lint",
1616
"postpublish": "npm run deploy",
17-
"prepublish": "npm run build",
1817
"start": "webpack-dev-server --hot --inline --config webpack.config.dev.js",
1918
"test": "cross-env NODE_ENV=test karma start",
2019
"watch": "watch 'clear && npm run lint -s && npm run test -s' src"
@@ -83,11 +82,9 @@
8382
"lodash": "^4.17.10",
8483
"mocha": "^2.3.4",
8584
"phantomjs2": "^2.0.2",
86-
"react": "^15.1.0",
87-
"react-dom": "^15.1.0",
88-
"react-transform-catch-errors": "^1.0.0",
85+
"react": "^18.0.0",
86+
"react-dom": "^18.0.0",
8987
"react-transform-hmr": "^1.0.1",
90-
"redbox-react": "1.2.6",
9188
"rimraf": "^2.4.4",
9289
"standard": "^5.4.1",
9390
"style-loader": "^0.13.0",
@@ -102,6 +99,6 @@
10299
"prop-types": "^15.5.8"
103100
},
104101
"peerDependencies": {
105-
"react": "^0.14.0 || ^15.0.0 || ^16.0.0-0 || ^17.0.0-0"
102+
"react": "^0.14.0 || ^15.0.0 || ^16.0.0-0 || ^17.0.0-0 || ^18.0.0-0"
106103
}
107104
}

webpack.config.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const HtmlWebpackPlugin = require('html-webpack-plugin')
2+
const path = require('path')
3+
const webpack = require('webpack')
4+
5+
module.exports = {
6+
devtool: 'eval',
7+
entry: [
8+
'babel/polyfill',
9+
'./website/index.js'
10+
],
11+
output: {
12+
path: 'build',
13+
filename: '/static/[name].js'
14+
},
15+
plugins: [
16+
new HtmlWebpackPlugin({
17+
filename: 'index.html',
18+
inject: true,
19+
template: './website/index.html'
20+
}),
21+
new webpack.NoErrorsPlugin(),
22+
new webpack.DefinePlugin({
23+
'process.env': {
24+
// to temporarily suppress "ReactDOM.render is no longer supported in React 18" warnings
25+
// should be removed after switching to createRoot
26+
'NODE_ENV': JSON.stringify('production')
27+
}
28+
})
29+
],
30+
module: {
31+
loaders: [
32+
{
33+
test: /\.js$/,
34+
loader: 'babel',
35+
exclude: path.join(__dirname, 'node_modules')
36+
},
37+
{
38+
test: /\.css$/,
39+
loaders: ['style', 'css?modules&importLoaders=1', 'cssnext'],
40+
exclude: path.join(__dirname, 'node_modules')
41+
}
42+
]
43+
}
44+
}

website/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/**
2-
* This is the entray point to the documentation/demo/test harness site for react-highlight-words.
2+
* This is the entry point to the documentation/demo/test harness site for react-highlight-words.
33
* This target is published to the root of the `gh-pages` branch.
44
* @flow
55
*/
66
import Application from './Application'
77
import React from 'react'
8-
import { render } from 'react-dom'
8+
import { createRoot } from 'react-dom/client'
99
import './index.css'
1010

11-
render(
12-
<Application/>,
13-
document.getElementById('root')
14-
)
11+
const root = createRoot(document.getElementById('root'))
12+
root.render(<Application/>)

yarn.lock

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,14 +1075,6 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
10751075
version "1.0.2"
10761076
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
10771077

1078-
create-react-class@^15.6.0:
1079-
version "15.6.2"
1080-
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.2.tgz#cf1ed15f12aad7f14ef5f2dfe05e6c42f91ef02a"
1081-
dependencies:
1082-
fbjs "^0.8.9"
1083-
loose-envify "^1.3.1"
1084-
object-assign "^4.1.1"
1085-
10861078
cross-env@^5.1.3:
10871079
version "5.1.3"
10881080
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.1.3.tgz#f8ae18faac87692b0a8b4d2f7000d4ec3a85dfd7"
@@ -1606,12 +1598,6 @@ errno@^0.1.3:
16061598
dependencies:
16071599
prr "~0.0.0"
16081600

1609-
error-stack-parser@^1.3.6:
1610-
version "1.3.6"
1611-
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-1.3.6.tgz#e0e73b93e417138d1cd7c0b746b1a4a14854c292"
1612-
dependencies:
1613-
stackframe "^0.3.1"
1614-
16151601
es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14:
16161602
version "0.10.35"
16171603
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.35.tgz#18ee858ce6a3c45c7d79e91c15fcca9ec568494f"
@@ -2011,7 +1997,7 @@ faye-websocket@~0.11.0:
20111997
dependencies:
20121998
websocket-driver ">=0.5.1"
20131999

2014-
fbjs@^0.8.16, fbjs@^0.8.9:
2000+
fbjs@^0.8.16:
20152001
version "0.8.16"
20162002
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
20172003
dependencies:
@@ -4685,7 +4671,7 @@ promise@^7.1.1:
46854671
dependencies:
46864672
asap "~2.0.3"
46874673

4688-
prop-types@^15.5.10, prop-types@^15.5.8:
4674+
prop-types@^15.5.8:
46894675
version "15.6.0"
46904676
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.0.tgz#ceaf083022fc46b4a35f69e13ef75aed0d639856"
46914677
dependencies:
@@ -4815,14 +4801,13 @@ react-deep-force-update@^1.0.0:
48154801
version "1.1.1"
48164802
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.1.1.tgz#bcd31478027b64b3339f108921ab520b4313dc2c"
48174803

4818-
react-dom@^15.1.0:
4819-
version "15.6.2"
4820-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.2.tgz#41cfadf693b757faf2708443a1d1fd5a02bef730"
4804+
react-dom@^18.0.0:
4805+
version "18.0.0"
4806+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023"
4807+
integrity sha512-XqX7uzmFo0pUceWFCt7Gff6IyIMzFUn7QMZrbrQfGxtaxXZIcGQzoNpRLE3fQLnS4XzLLPMZX2T9TRcSrasicw==
48214808
dependencies:
4822-
fbjs "^0.8.9"
48234809
loose-envify "^1.1.0"
4824-
object-assign "^4.1.0"
4825-
prop-types "^15.5.10"
4810+
scheduler "^0.21.0"
48264811

48274812
react-proxy@^1.1.7:
48284813
version "1.1.8"
@@ -4831,26 +4816,19 @@ react-proxy@^1.1.7:
48314816
lodash "^4.6.1"
48324817
react-deep-force-update "^1.0.0"
48334818

4834-
react-transform-catch-errors@^1.0.0:
4835-
version "1.0.2"
4836-
resolved "https://registry.yarnpkg.com/react-transform-catch-errors/-/react-transform-catch-errors-1.0.2.tgz#1b4d4a76e97271896fc16fe3086c793ec88a9eeb"
4837-
48384819
react-transform-hmr@^1.0.1:
48394820
version "1.0.4"
48404821
resolved "https://registry.yarnpkg.com/react-transform-hmr/-/react-transform-hmr-1.0.4.tgz#e1a40bd0aaefc72e8dfd7a7cda09af85066397bb"
48414822
dependencies:
48424823
global "^4.3.0"
48434824
react-proxy "^1.1.7"
48444825

4845-
react@^15.1.0:
4846-
version "15.6.2"
4847-
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
4826+
react@^18.0.0:
4827+
version "18.0.0"
4828+
resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96"
4829+
integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A==
48484830
dependencies:
4849-
create-react-class "^15.6.0"
4850-
fbjs "^0.8.9"
48514831
loose-envify "^1.1.0"
4852-
object-assign "^4.1.0"
4853-
prop-types "^15.5.10"
48544832

48554833
read-file-stdin@^0.2.0:
48564834
version "0.2.1"
@@ -4934,13 +4912,6 @@ recast@^0.11.17:
49344912
private "~0.1.5"
49354913
source-map "~0.5.0"
49364914

4937-
redbox-react@1.2.6:
4938-
version "1.2.6"
4939-
resolved "https://registry.yarnpkg.com/redbox-react/-/redbox-react-1.2.6.tgz#b88f5b5c579b4bbf23fa2ddd535285346aa89abc"
4940-
dependencies:
4941-
error-stack-parser "^1.3.6"
4942-
object-assign "^4.0.1"
4943-
49444915
reduce-css-calc@^1.2.0, reduce-css-calc@^1.2.6:
49454916
version "1.3.0"
49464917
resolved "https://registry.yarnpkg.com/reduce-css-calc/-/reduce-css-calc-1.3.0.tgz#747c914e049614a4c9cfbba629871ad1d2927716"
@@ -5224,6 +5195,13 @@ sax@~1.2.1:
52245195
version "1.2.4"
52255196
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
52265197

5198+
scheduler@^0.21.0:
5199+
version "0.21.0"
5200+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.21.0.tgz#6fd2532ff5a6d877b6edb12f00d8ab7e8f308820"
5201+
integrity sha512-1r87x5fz9MXqswA2ERLo0EbOAU74DpIUO090gIasYTqlVoJeMcl+Z1Rg7WHz+qtPujhS/hGIt9kxZOYBV3faRQ==
5202+
dependencies:
5203+
loose-envify "^1.1.0"
5204+
52275205
"semver@2 || 3 || 4", semver@^4.3.1, semver@~4.3.3:
52285206
version "4.3.6"
52295207
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"
@@ -5492,10 +5470,6 @@ stable@~0.1.3:
54925470
version "0.1.6"
54935471
resolved "https://registry.yarnpkg.com/stable/-/stable-0.1.6.tgz#910f5d2aed7b520c6e777499c1f32e139fdecb10"
54945472

5495-
stackframe@^0.3.1:
5496-
version "0.3.1"
5497-
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-0.3.1.tgz#33aa84f1177a5548c8935533cbfeb3420975f5a4"
5498-
54995473
standard-engine@^2.0.4:
55005474
version "2.2.5"
55015475
resolved "https://registry.yarnpkg.com/standard-engine/-/standard-engine-2.2.5.tgz#a2b9d4419f648a221b8d17823fb745406f37c34e"

0 commit comments

Comments
 (0)