diff --git a/packages/react-components/src/InputStorage/index.tsx b/packages/react-components/src/InputStorage/index.tsx index 7d80ecdb53..5dc18da813 100644 --- a/packages/react-components/src/InputStorage/index.tsx +++ b/packages/react-components/src/InputStorage/index.tsx @@ -30,31 +30,27 @@ function InputStorage ({ className = '', defaultValue, help, label, onChange, wi const { api } = useApi(); const [optionsMethod, setOptionsMethod] = useState(() => keyOptions(api, defaultValue.creator.section)); const [optionsSection] = useState(() => sectionOptions(api)); - const [value, setValue] = useState>(defaultValue); + const [value, setValue] = useState>(() => defaultValue); const _onKeyChange = useCallback( (newValue: QueryableStorageEntry<'promise'>): void => { - if (value.creator.section === newValue.creator.section && value.creator.method === newValue.creator.method) { - return; + if (value.creator.section !== newValue.creator.section || value.creator.method !== newValue.creator.method) { + // set via callback + setValue(() => newValue); + onChange && onChange(newValue); } - - // set via callback - setValue(() => newValue); - onChange && onChange(newValue); }, [onChange, value] ); const _onSectionChange = useCallback( (section: string): void => { - if (section === value.creator.section) { - return; + if (section !== value.creator.section) { + const optionsMethod = keyOptions(api, section); + + setOptionsMethod(optionsMethod); + _onKeyChange(api.query[section][optionsMethod[0].value] as any); } - - const optionsMethod = keyOptions(api, section); - - setOptionsMethod(optionsMethod); - _onKeyChange(api.query[section][optionsMethod[0].value] as any); }, [_onKeyChange, api, value] );