@etsoo/react 1.4.47 → 1.4.48

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,16 +10,18 @@ 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
19
  // When options change
20
+ // [options] will cause infinite loop
20
21
  React.useEffect(() => {
21
- setOptions(options);
22
- }, [options]);
22
+ if (options != null)
23
+ setOptions(options);
24
+ }, [JSON.stringify(options)]);
23
25
  // Local default value
24
26
  let localValue = idValue != null
25
27
  ? localOptions.find((o) => Reflect.get(o, idField) === idValue)
@@ -16,9 +16,11 @@ export function SelectEx(props) {
16
16
  const [localOptions, setOptions] = React.useState(options);
17
17
  const isMounted = React.useRef(true);
18
18
  // When options change
19
+ // [options] will cause infinite loop
19
20
  React.useEffect(() => {
20
- setOptions(options);
21
- }, [options]);
21
+ if (options != null)
22
+ setOptions(options);
23
+ }, [JSON.stringify(options)]);
22
24
  // Local value
23
25
  const valueSource = (_a = defaultValue !== null && defaultValue !== void 0 ? defaultValue : value) !== null && _a !== void 0 ? _a : '';
24
26
  let localValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.47",
3
+ "version": "1.4.48",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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,13 +69,14 @@ 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
75
  // When options change
76
+ // [options] will cause infinite loop
76
77
  React.useEffect(() => {
77
- setOptions(options);
78
- }, [options]);
78
+ if (options != null) setOptions(options);
79
+ }, [JSON.stringify(options)]);
79
80
 
80
81
  // Local default value
81
82
  let localValue =
@@ -91,9 +91,10 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
91
91
  const isMounted = React.useRef(true);
92
92
 
93
93
  // When options change
94
+ // [options] will cause infinite loop
94
95
  React.useEffect(() => {
95
- setOptions(options);
96
- }, [options]);
96
+ if (options != null) setOptions(options);
97
+ }, [JSON.stringify(options)]);
97
98
 
98
99
  // Local value
99
100
  const valueSource = defaultValue ?? value ?? '';