@lingui/react 4.7.1 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -8,14 +8,19 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
8
8
  const React__default = /*#__PURE__*/_interopDefaultCompat(React);
9
9
 
10
10
  const LinguiContext = React__default.createContext(null);
11
- function useLingui() {
11
+ const useLinguiInternal = (devErrorMessage) => {
12
12
  const context = React__default.useContext(LinguiContext);
13
13
  if (process.env.NODE_ENV !== "production") {
14
14
  if (context == null) {
15
- throw new Error("useLingui hook was used without I18nProvider.");
15
+ throw new Error(
16
+ devErrorMessage ?? "useLingui hook was used without I18nProvider."
17
+ );
16
18
  }
17
19
  }
18
20
  return context;
21
+ };
22
+ function useLingui() {
23
+ return useLinguiInternal();
19
24
  }
20
25
  const I18nProvider = ({
21
26
  i18n,
@@ -53,7 +58,12 @@ const I18nProvider = ({
53
58
  };
54
59
 
55
60
  function Trans(props) {
56
- const lingui = useLingui();
61
+ let errMessage = void 0;
62
+ if (process.env.NODE_ENV !== "production") {
63
+ errMessage = `Trans component was rendered without I18nProvider.
64
+ Attempted to render message: ${props.message} id: ${props.id}. Make sure this component is rendered inside a I18nProvider.`;
65
+ }
66
+ const lingui = useLinguiInternal(errMessage);
57
67
  return React__default.createElement(server.TransNoContext, { ...props, lingui });
58
68
  }
59
69
 
package/dist/index.mjs CHANGED
@@ -2,14 +2,19 @@ import React from 'react';
2
2
  import { TransNoContext } from './server.mjs';
3
3
 
4
4
  const LinguiContext = React.createContext(null);
5
- function useLingui() {
5
+ const useLinguiInternal = (devErrorMessage) => {
6
6
  const context = React.useContext(LinguiContext);
7
7
  if (process.env.NODE_ENV !== "production") {
8
8
  if (context == null) {
9
- throw new Error("useLingui hook was used without I18nProvider.");
9
+ throw new Error(
10
+ devErrorMessage ?? "useLingui hook was used without I18nProvider."
11
+ );
10
12
  }
11
13
  }
12
14
  return context;
15
+ };
16
+ function useLingui() {
17
+ return useLinguiInternal();
13
18
  }
14
19
  const I18nProvider = ({
15
20
  i18n,
@@ -47,7 +52,12 @@ const I18nProvider = ({
47
52
  };
48
53
 
49
54
  function Trans(props) {
50
- const lingui = useLingui();
55
+ let errMessage = void 0;
56
+ if (process.env.NODE_ENV !== "production") {
57
+ errMessage = `Trans component was rendered without I18nProvider.
58
+ Attempted to render message: ${props.message} id: ${props.id}. Make sure this component is rendered inside a I18nProvider.`;
59
+ }
60
+ const lingui = useLinguiInternal(errMessage);
51
61
  return React.createElement(TransNoContext, { ...props, lingui });
52
62
  }
53
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/react",
3
- "version": "4.7.1",
3
+ "version": "4.7.2",
4
4
  "sideEffects": false,
5
5
  "description": "React components for translations",
6
6
  "main": "./dist/index.cjs",
@@ -73,7 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@babel/runtime": "^7.20.13",
76
- "@lingui/core": "4.7.1"
76
+ "@lingui/core": "4.7.2"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@lingui/jest-mocks": "*",
@@ -85,5 +85,5 @@
85
85
  "react-dom": "^18.2.0",
86
86
  "unbuild": "2.0.0"
87
87
  },
88
- "gitHead": "49647102dbbd7046a2c318ba0525c1392e370076"
88
+ "gitHead": "f15ce1520efcf33fefc160f6f59fa86ead3183a3"
89
89
  }