Skip to content

Commit

Permalink
fix(*): fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
shangqunfeng committed Jun 2, 2024
1 parent a464717 commit 4fd0e5c
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function wrapImage(imageStyle) {
const show = useRef(false)
const imageSize = useRef(null)
const layoutInfo = useRef(null)
const [_, forceUpdate] = useState({})
const [_, forceUpdate] = useState({}) // 用于布局变化,图片变化时,重新渲染。

// 预解析
const preImageInfo = preParseImage(imageStyle)
Expand Down Expand Up @@ -201,6 +201,7 @@ function wrapImage(imageStyle) {
}
}, [preImageInfo?.src])

// 避免hook数量不一致引起的报错
if (!preImageInfo) return null

if (!sizeList.includes('auto')) {
Expand All @@ -213,6 +214,8 @@ function wrapImage(imageStyle) {
height: layout.height,
width: layout.width
}
// 布局变化时,要重新的渲染
// show为useState时,这里无法重新的渲染
if (imageSize.current) {
show.current = true
forceUpdate({})
Expand Down

0 comments on commit 4fd0e5c

Please sign in to comment.