Skip to content

Commit

Permalink
Return the default value if it's not true or false.
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hiyak committed Nov 28, 2024
1 parent 3552972 commit ff39fc9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/atomWithSearchParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export const atomWithSearchParams = <T>(
return Number(value) as T;
}

// If the default value is a boolean, check if the value is `true` or `false`.
if (typeof defaultValue === 'boolean') {
return (value === 'true') as T;
if (value === 'true') return true as T;
if (value === 'false') return false as T;
return defaultValue;
}

if (typeof defaultValue === 'string') {
Expand Down

0 comments on commit ff39fc9

Please sign in to comment.