@etsoo/react 1.4.46 → 1.4.50

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.
@@ -10,12 +10,19 @@ import { SearchField } from './SearchField';
10
10
  */
11
11
  export function ComboBox(props) {
12
12
  // Destruct
13
- const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options = [], readOnly = true, onChange, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
13
+ const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, readOnly = true, onChange, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
14
14
  // Value input ref
15
15
  const inputRef = React.createRef();
16
16
  // Options state
17
- const [localOptions, setOptions] = React.useState(options);
17
+ const [localOptions, setOptions] = React.useState(options !== null && options !== void 0 ? options : []);
18
18
  const isMounted = React.useRef(true);
19
+ // When options change
20
+ // [options] will cause infinite loop
21
+ const propertyWay = loadData == null;
22
+ React.useEffect(() => {
23
+ if (propertyWay && options != null)
24
+ setOptions(options);
25
+ }, [JSON.stringify(options), propertyWay]);
19
26
  // Local default value
20
27
  let localValue = idValue != null
21
28
  ? localOptions.find((o) => Reflect.get(o, idField) === idValue)
@@ -15,6 +15,13 @@ export function SelectEx(props) {
15
15
  // Options state
16
16
  const [localOptions, setOptions] = React.useState(options);
17
17
  const isMounted = React.useRef(true);
18
+ // When options change
19
+ // [options] will cause infinite loop
20
+ const propertyWay = loadData == null;
21
+ React.useEffect(() => {
22
+ if (propertyWay && options != null)
23
+ setOptions(options);
24
+ }, [JSON.stringify(options), propertyWay]);
18
25
  // Local value
19
26
  const valueSource = (_a = defaultValue !== null && defaultValue !== void 0 ? defaultValue : value) !== null && _a !== void 0 ? _a : '';
20
27
  let localValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.46",
3
+ "version": "1.4.50",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,11 +50,11 @@
50
50
  "@emotion/react": "^11.7.1",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.6.0",
53
- "@etsoo/appscript": "^1.2.24",
53
+ "@etsoo/appscript": "^1.2.25",
54
54
  "@etsoo/notificationbase": "^1.1.0",
55
- "@etsoo/shared": "^1.1.3",
56
- "@mui/icons-material": "^5.2.5",
57
- "@mui/material": "^5.2.8",
55
+ "@etsoo/shared": "^1.1.5",
56
+ "@mui/icons-material": "^5.3.0",
57
+ "@mui/material": "^5.3.0",
58
58
  "@reach/router": "^1.3.4",
59
59
  "@types/pica": "^5.1.3",
60
60
  "@types/pulltorefreshjs": "^0.1.5",
@@ -83,9 +83,9 @@
83
83
  "@babel/runtime-corejs3": "^7.16.8",
84
84
  "@types/jest": "^27.4.0",
85
85
  "@types/react-test-renderer": "^17.0.1",
86
- "@typescript-eslint/eslint-plugin": "^5.9.1",
87
- "@typescript-eslint/parser": "^5.9.1",
88
- "eslint": "^8.6.0",
86
+ "@typescript-eslint/eslint-plugin": "^5.10.0",
87
+ "@typescript-eslint/parser": "^5.10.0",
88
+ "eslint": "^8.7.0",
89
89
  "eslint-config-airbnb-base": "^15.0.0",
90
90
  "eslint-plugin-import": "^2.25.4",
91
91
  "eslint-plugin-react": "^7.28.0",
@@ -56,7 +56,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
56
56
  onLoadData,
57
57
  name,
58
58
  inputAutoComplete = 'off',
59
- options = [],
59
+ options,
60
60
  readOnly = true,
61
61
  onChange,
62
62
  value,
@@ -69,9 +69,16 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
69
69
  const inputRef = React.createRef<HTMLInputElement>();
70
70
 
71
71
  // Options state
72
- const [localOptions, setOptions] = React.useState(options);
72
+ const [localOptions, setOptions] = React.useState(options ?? []);
73
73
  const isMounted = React.useRef(true);
74
74
 
75
+ // When options change
76
+ // [options] will cause infinite loop
77
+ const propertyWay = loadData == null;
78
+ React.useEffect(() => {
79
+ if (propertyWay && options != null) setOptions(options);
80
+ }, [JSON.stringify(options), propertyWay]);
81
+
75
82
  // Local default value
76
83
  let localValue =
77
84
  idValue != null
@@ -90,6 +90,13 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
90
90
  const [localOptions, setOptions] = React.useState(options);
91
91
  const isMounted = React.useRef(true);
92
92
 
93
+ // When options change
94
+ // [options] will cause infinite loop
95
+ const propertyWay = loadData == null;
96
+ React.useEffect(() => {
97
+ if (propertyWay && options != null) setOptions(options);
98
+ }, [JSON.stringify(options), propertyWay]);
99
+
93
100
  // Local value
94
101
  const valueSource = defaultValue ?? value ?? '';
95
102
  let localValue: unknown | unknown[];