🚨fix: QSelectBox 외부에서 값 변경 함수 추가

This commit is contained in:
yoosangwook 2024-12-26 14:50:54 +09:00
parent 7cebd22047
commit 4ce2ff4a45
2 changed files with 14 additions and 6 deletions

View File

@ -200,7 +200,7 @@ export default function Playground() {
}, },
] ]
const myData = { const [myData, setMyData] = useState({
roofMatlCd: 'ROOF_ID_WA_53A', roofMatlCd: 'ROOF_ID_WA_53A',
roofMatlNm: '화와 A', roofMatlNm: '화와 A',
roofMatlNmJp: '和瓦A', roofMatlNmJp: '和瓦A',
@ -220,6 +220,10 @@ export default function Playground() {
width: 265, width: 265,
layout: 'P', layout: 'P',
hajebichi: null, hajebichi: null,
})
const handleChangeMyData = () => {
setMyData({ ...myData, raftBaseCd: 'HEI_500' })
} }
return ( return (
@ -497,6 +501,9 @@ export default function Playground() {
<div className="my-2"> <div className="my-2">
<QSelectBox options={codes} value={myData} sourceKey="id" targetKey="raftBaseCd" showKey="clCodeNm" /> <QSelectBox options={codes} value={myData} sourceKey="id" targetKey="raftBaseCd" showKey="clCodeNm" />
</div> </div>
<div className="my-2">
<Button onClick={handleChangeMyData}>QSelectBox value change!!</Button>
</div>
</div> </div>
</> </>
) )

View File

@ -1,5 +1,5 @@
'use client' 'use client'
import { useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { useOnClickOutside } from 'usehooks-ts' import { useOnClickOutside } from 'usehooks-ts'
/** /**
@ -54,7 +54,7 @@ export default function QSelectBox({
const ref = useRef(null) const ref = useRef(null)
const handleClickSelectOption = (option) => { const handleClickSelectOption = (option) => {
setSelected(option.name) setSelected(showKey !== '' ? option[showKey] : option.name)
onChange?.(option, params) onChange?.(option, params)
} }
@ -62,9 +62,10 @@ export default function QSelectBox({
setOpenSelect(false) setOpenSelect(false)
} }
// useEffect(() => { useEffect(() => {
// value && handleClickSelectOption(value) // value && handleClickSelectOption(value)
// }, [value]) setSelected(handleInitState())
}, [value])
useOnClickOutside(ref, handleClose) useOnClickOutside(ref, handleClose)