Skip to content

Commit 5786046

Browse files
committed
chore: use effect to sync searchParams
1 parent 6775dc1 commit 5786046

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

website/app/components/navbar/options.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSearchParams } from "@remix-run/react";
33
import { Input } from "@/ui/input";
44
import { Slider } from "@/ui/slider";
55
import { iconSizeParamKey, searchParamKey } from "@/data/searchParams";
6+
import { useEffect, useState } from "react";
67

78
interface iSearchProps {
89
className?: string;
@@ -40,7 +41,9 @@ export const Search = (props: iSearchProps) => {
4041
// 📏 Icon Size Slider:
4142
export const IconSize = () => {
4243
const [searchParams, setSearchParams] = useSearchParams();
43-
const iconSizeValue = searchParams.get(iconSizeParamKey) || 45;
44+
const [iconSizeValue, setIconSizeValue] = useState(
45+
Number(searchParams.get(iconSizeParamKey)) || 45,
46+
);
4447

4548
const handleChange = (value: number[]) => {
4649
const newSearchParams = new URLSearchParams(searchParams);
@@ -52,11 +55,15 @@ export const IconSize = () => {
5255
setSearchParams(newSearchParams);
5356
};
5457

58+
useEffect(() => {
59+
handleChange([iconSizeValue]);
60+
}, [iconSizeValue]);
61+
5562
return (
5663
<Slider
5764
title="Icon Size"
58-
defaultValue={[Number(iconSizeValue)]}
59-
onValueChange={(value) => handleChange(value)}
65+
value={[Number(iconSizeValue)]}
66+
onValueChange={(value) => setIconSizeValue(value[0])}
6067
max={70}
6168
min={20}
6269
step={1}

0 commit comments

Comments
 (0)