Skip to content

Commit 5992802

Browse files
committed
fix: esm build
1 parent 0ed8e60 commit 5992802

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
"preset": "@4c/jest-preset"
4747
},
4848
"dependencies": {
49-
"@restart/hooks": "^0.3.15",
5049
"@types/react": ">=16.8.0",
5150
"@types/react-relay": ">=4.0.0",
52-
"@types/relay-runtime": ">=4.0.0",
53-
"invariant": "^2.2.4"
51+
"@types/relay-runtime": ">=4.0.0"
5452
},
5553
"devDependencies": {
5654
"@4c/babel-preset": "^8.0.1",
@@ -106,7 +104,6 @@
106104
"relay-runtime": ">=2.0.0"
107105
},
108106
"publishConfig": {
109-
"access": "public",
110-
"directory": "lib"
107+
"access": "public"
111108
}
112109
}

src/index.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import useMounted from '@restart/hooks/useMounted';
2-
import invariant from 'invariant';
3-
import React, { useCallback, useContext, useState } from 'react';
1+
import React, {
2+
useCallback,
3+
useContext,
4+
useEffect,
5+
useRef,
6+
useState,
7+
} from 'react';
48
import { ReactRelayContext, commitMutation } from 'react-relay';
59
import {
610
MutationConfig as BaseMutationConfig,
@@ -40,7 +44,14 @@ export function useMutation<T extends MutationParameters>(
4044
error: null,
4145
});
4246

43-
const isMounted = useMounted();
47+
const mounted = useRef(true);
48+
49+
useEffect(
50+
() => () => {
51+
mounted.current = false;
52+
},
53+
[],
54+
);
4455

4556
const relayContext = useContext(ReactRelayContext);
4657
const resolvedEnvironment = environment || relayContext!.environment;
@@ -69,7 +80,9 @@ export function useMutation<T extends MutationParameters>(
6980
...config,
7081
};
7182

72-
invariant(mergedConfig.variables, 'you must specify variables');
83+
if (!mergedConfig.variables) {
84+
throw Error('you must specify variables');
85+
}
7386

7487
setState({
7588
loading: true,
@@ -79,7 +92,7 @@ export function useMutation<T extends MutationParameters>(
7992

8093
return new Promise((resolve, reject) => {
8194
function handleError(error: any) {
82-
if (isMounted()) {
95+
if (mounted.current) {
8396
setState({
8497
loading: false,
8598
data: null,
@@ -106,7 +119,7 @@ export function useMutation<T extends MutationParameters>(
106119
return;
107120
}
108121

109-
if (isMounted()) {
122+
if (mounted.current) {
110123
setState({
111124
loading: false,
112125
data: response,
@@ -134,7 +147,6 @@ export function useMutation<T extends MutationParameters>(
134147
optimisticUpdater,
135148
optimisticResponse,
136149
updater,
137-
isMounted,
138150
],
139151
);
140152

yarn.lock

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,14 +1394,6 @@
13941394
"@nodelib/fs.scandir" "2.1.3"
13951395
fastq "^1.6.0"
13961396

1397-
"@restart/hooks@^0.3.15":
1398-
version "0.3.25"
1399-
resolved "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.3.25.tgz#11004139ad1c70d2f5965a8939dcb5aeb96aa652"
1400-
integrity sha512-m2v3N5pxTsIiSH74/sb1yW8D9RxkJidGW+5Mfwn/lHb2QzhZNlaU1su7abSyT9EGf0xS/0waLjrf7/XxQHUk7w==
1401-
dependencies:
1402-
lodash "^4.17.15"
1403-
lodash-es "^4.17.15"
1404-
14051397
"@samverschueren/stream-to-observable@^0.3.0":
14061398
version "0.3.0"
14071399
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
@@ -5778,11 +5770,6 @@ locate-path@^6.0.0:
57785770
dependencies:
57795771
p-locate "^5.0.0"
57805772

5781-
lodash-es@^4.17.15:
5782-
version "4.17.15"
5783-
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
5784-
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==
5785-
57865773
lodash._reinterpolate@^3.0.0:
57875774
version "3.0.0"
57885775
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"

0 commit comments

Comments
 (0)