Skip to content

Commit

Permalink
fix: Allow state updates in Snaps interfaces to state values that are…
Browse files Browse the repository at this point in the history
… falsy
  • Loading branch information
FrederikBolding committed Sep 30, 2024
1 parent d1b778c commit 2ab2f28
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const SnapUIDropdown: FunctionComponent<SnapUIDropdownProps> = ({
const [value, setValue] = useState(initialValue ?? '');

useEffect(() => {
if (initialValue) {
if (initialValue !== undefined && initialValue !== null) {
setValue(initialValue);
}
}, [initialValue]);
Expand Down
2 changes: 1 addition & 1 deletion ui/components/app/snaps/snap-ui-input/snap-ui-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const SnapUIInput: FunctionComponent<
const [value, setValue] = useState(initialValue ?? '');

useEffect(() => {
if (initialValue) {
if (initialValue !== undefined && initialValue !== null) {
setValue(initialValue);
}
}, [initialValue]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const SnapUISelector: React.FunctionComponent<SnapUISelectorProps> = ({
const [isModalOpen, setIsModalOpen] = useState(false);

useEffect(() => {
if (initialValue) {
if (initialValue !== undefined && initialValue !== null) {
setSelectedOption(initialValue);
}
}, [initialValue]);
Expand Down
2 changes: 1 addition & 1 deletion ui/contexts/snaps/snap-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const SnapInterfaceContextProvider: FunctionComponent<
? (initialState[form] as FormState)?.[name]
: (initialState as FormState)?.[name];

if (value) {
if (value !== undefined && value !== null) {
return value;
}

Expand Down

0 comments on commit 2ab2f28

Please sign in to comment.