Skip to content

Commit 8c499e9

Browse files
authored
fix(collapse): fix bug in strict mode(#605) (#606)
1 parent b2ba223 commit 8c499e9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/react-vant/src/components/collapse/Collapse.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ const [bem] = createNamespace('collapse')
2828

2929
const Collapse: React.FC<CollapseProps> = props => {
3030
const { accordion } = props
31-
const initExpandedDefault = accordion ? '' : []
32-
const { initExpanded = initExpandedDefault } = props
31+
const { initExpanded = accordion ? '' : [] } = props
3332
const innerEffect = useRef(false)
34-
const [expanded, setExpanded] = useState(() => props.value ?? initExpanded)
33+
const [expanded, setExpanded] = useState<
34+
string | number | Array<number | string>
35+
>(() => props.value ?? initExpanded)
3536
const updateName = (name: number | string | Array<number | string>) => {
3637
innerEffect.current = true
3738
setExpanded(name)
@@ -69,6 +70,7 @@ const Collapse: React.FC<CollapseProps> = props => {
6970
innerEffect.current = false
7071
return
7172
}
73+
if (props.value === undefined) return
7274
setExpanded(props.value)
7375
}, [props.value])
7476

0 commit comments

Comments
 (0)