Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e36e168

Browse files
authored
React 18 support (#440)
1 parent f42020c commit e36e168

File tree

6 files changed

+176
-127
lines changed

6 files changed

+176
-127
lines changed

.github/workflows/tests.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- uses: CultureHQ/actions-yarn@master
14-
with:
15-
args: install
16-
- uses: CultureHQ/actions-yarn@master
17-
with:
18-
args: test
13+
- uses: actions/setup-node@v2
14+
- run: yarn install
15+
- run: yarn test

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
],
6060
"peerDependencies": {
6161
"@popperjs/core": "^2.0.0",
62-
"react": "^16.8.0 || ^17"
62+
"react": "^16.8.0 || ^17 || ^18",
63+
"react-dom": "^16.8.0 || ^17 || ^18"
6364
},
6465
"dependencies": {
6566
"react-fast-compare": "^3.0.1",
@@ -80,8 +81,8 @@
8081
"@rollup/plugin-commonjs": "^11.0.2",
8182
"@rollup/plugin-node-resolve": "^7.1.1",
8283
"@rollup/plugin-replace": "^2.3.1",
83-
"@testing-library/react": "^10.0.2",
84-
"@testing-library/react-hooks": "^3.2.1",
84+
"@testing-library/react": "^13.1.1",
85+
"@testing-library/react-hooks": "^8.0.0",
8586
"@types/react": "^16.9.29",
8687
"babel-eslint": "^10.1.0",
8788
"babel-jest": "^25.2.4",
@@ -93,18 +94,18 @@
9394
"eslint-plugin-promise": "^4.2.1",
9495
"eslint-plugin-react": "^7.19.0",
9596
"eslint-plugin-react-hooks": "^3.0.0",
96-
"flow-bin": "^0.147.0",
97+
"flow-bin": "^0.176.2",
9798
"flow-copy-source": "^2.0.9",
9899
"gh-pages": "^2.2.0",
99100
"git-branch-is": "^3.1.0",
100101
"jest": "^25.2.4",
101102
"parcel-bundler": "^1.12.4",
102103
"prettier": "^2.0.2",
103104
"pretty-quick": "^2.0.1",
104-
"react": "17.0.0",
105-
"react-dom": "^17.0.0",
105+
"react": "18.0.0",
106+
"react-dom": "^18.0.0",
106107
"react-spring": "^8.0.27",
107-
"react-test-renderer": "^17.0.0",
108+
"react-test-renderer": "^18.0.0",
108109
"rimraf": "^3.0.2",
109110
"rollup": "^2.3.1",
110111
"rollup-plugin-babel": "^4.4.0",

src/Reference.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function Reference({ children, innerRef }: ReferenceProps): React.Node {
2323
);
2424

2525
// ran on unmount
26+
// eslint-disable-next-line react-hooks/exhaustive-deps
2627
React.useEffect(() => () => setRef(innerRef, null), []);
2728

2829
React.useEffect(() => {

src/usePopper.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow strict
22
import * as React from 'react';
3+
import * as ReactDOM from 'react-dom';
34
import {
45
createPopper as defaultCreatePopper,
56
type Options as PopperOptions,
@@ -74,13 +75,15 @@ export const usePopper = (
7475
fn: ({ state }) => {
7576
const elements = Object.keys(state.elements);
7677

77-
setState({
78-
styles: fromEntries(
79-
elements.map(element => [element, state.styles[element] || {}])
80-
),
81-
attributes: fromEntries(
82-
elements.map(element => [element, state.attributes[element]])
83-
),
78+
ReactDOM.flushSync(() => {
79+
setState({
80+
styles: fromEntries(
81+
elements.map((element) => [element, state.styles[element] || {}])
82+
),
83+
attributes: fromEntries(
84+
elements.map((element) => [element, state.attributes[element]])
85+
),
86+
});
8487
});
8588
},
8689
requires: ['computeStyles'],

src/usePopper.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ describe('userPopper', () => {
1414
});
1515

1616
it('initializes the Popper instance', async () => {
17-
const { result, wait } = renderHook(() =>
17+
const { result, waitFor } = renderHook(() =>
1818
usePopper(referenceElement, popperElement)
1919
);
2020

21-
await wait(() => {
21+
await waitFor(() => {
2222
expect(result.current.state).not.toBe(null);
2323
});
2424
});
2525

2626
it("doesn't update Popper instance on props update if not needed by Popper", async () => {
2727
const spy = jest.spyOn(PopperJs, 'createPopper');
28-
const { wait, rerender } = renderHook(
28+
const { waitFor, rerender } = renderHook(
2929
({ referenceElement, popperElement }) =>
3030
usePopper(referenceElement, popperElement),
3131
{ initialProps: { referenceElement, popperElement } }
@@ -35,7 +35,7 @@ describe('userPopper', () => {
3535
await rerender({ referenceElement, popperElement });
3636
});
3737

38-
await wait(() => {
38+
await waitFor(() => {
3939
expect(spy).toHaveBeenCalledTimes(1);
4040
});
4141
});

0 commit comments

Comments
 (0)