-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Closed
Labels
Description
I have a button with action to set a sorting on select input. On that button i change the value on useState from latest -> price-low-high.
When the button clicked the value inside render-value class changed. but the default value for the select not changed.
const [sort, setSort] = useState<string>('latest')
<div className="flex items-center w-full md:w-auto">
<div className="render-value">{sort}</div>
<button onClick={()=> setSort('price-low-high')}>CHANGE SORT VALUE<button>
<Label htmlFor="sorting" className="mr-2 text-gray-500 hidden md:block">Sorting {sort}</Label>
<Select onValueChange={value=> selectSort(value)}
defaultValue={sort}>
<SelectTrigger className="w-full md:w-[200px]">
<SelectValue placeholder="Select Sorting" />
</SelectTrigger>
<SelectContent id="sorting">
<SelectItem value="latest">Latest Product {sort}</SelectItem>
<SelectItem value={'price-low-high'}>Price: Low - High</SelectItem>
<SelectItem value={'price-high-low'}>Price: High - Low</SelectItem>
</SelectContent>
</Select>
</div>
yousihy, mkue, GiantappMan, mr-scrpt, jackypan1989 and 20 more