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