refactor: Add init value in QselectBox
This commit is contained in:
parent
1c2d3b7968
commit
05a2d6abd0
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export default function QSelectBox({ title = '', options, onChange }) {
|
||||
export default function QSelectBox({ title = '', options, onChange, value }) {
|
||||
const [openSelect, setOpenSelect] = useState(false)
|
||||
const [selected, setSelected] = useState(title === '' ? options[0].name : title)
|
||||
|
||||
@ -10,6 +10,10 @@ export default function QSelectBox({ title = '', options, onChange }) {
|
||||
onChange?.(option)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
value && handleClickSelectOption(value)
|
||||
}, [value])
|
||||
|
||||
return (
|
||||
<div className={`sort-select ${openSelect ? 'active' : ''}`} onClick={() => setOpenSelect(!openSelect)}>
|
||||
<p>{selected}</p>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user