Skip to content

Commit 1346ff2

Browse files
committed
optimize WechatAPI error hint
1 parent 193cf9c commit 1346ff2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"dependencies": {
4343
"create-react-context": "^0.2.3",
4444
"emit-lite": "^2.0.0",
45-
"prop-types": "^15.5.7"
45+
"prop-types": "^15.5.7",
46+
"tiny-invariant": "^1.0.3"
4647
},
4748
"devDependencies": {
4849
"@babel/cli": "^7.1.2",

src/withWechatAPI.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import React, { PureComponent } from 'react';
22
import WechatAPIContext from './WechatAPIContext';
3+
import invariant from 'tiny-invariant';
34

45
export default function withWechatAPI(WrappedComponent) {
56
return class WechatAPIConsumer extends PureComponent {
67
renderChildren = (wechatAPI) => {
8+
invariant(
9+
wechatAPI,
10+
'You should not use <AppTitle> outside <WechatAPIProvider>',
11+
);
712
return <WrappedComponent {...this.props} wechatAPI={wechatAPI} />;
813
};
914

yarn.lock

+4
Original file line numberDiff line numberDiff line change
@@ -8591,6 +8591,10 @@ timers-browserify@^2.0.4:
85918591
dependencies:
85928592
setimmediate "^1.0.4"
85938593

8594+
tiny-invariant@^1.0.3:
8595+
version "1.0.3"
8596+
resolved "http://registry.npm.taobao.org/tiny-invariant/download/tiny-invariant-1.0.3.tgz#91efaaa0269ccb6271f0296aeedb05fc3e067b7a"
8597+
85948598
tmp@^0.0.29:
85958599
version "0.0.29"
85968600
resolved "http://registry.npm.taobao.org/tmp/download/tmp-0.0.29.tgz#f25125ff0dd9da3ccb0c2dd371ee1288bb9128c0"

0 commit comments

Comments
 (0)