You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-photo-album与ReactDOMServer.renderToStaticMarkup兼容问题求助

ReactDOMServer渲染react-photo-album无图片问题解决

问题现象

使用ReactDOMServer.renderToStaticMarkup渲染react-photo-album组件时,仅能生成空的react-photo-album--rows主容器,图片完全不渲染;但给组件添加defaultContainerWidth={300}参数后,图片可正常显示。

无效尝试

曾通过状态判断组件挂载状态,仅在mounted为true时渲染组件,该方案未解决问题:

const [mounted, setMounted] = useState(false);

useEffect(() => {
  setMounted(true)
}, []);

异常代码示例

ReactDOMServer.renderToStaticMarkup(<PhotoAlbum
  photos={photos}
  {...config}
/>);

解决代码

添加defaultContainerWidth参数即可修复渲染异常:

<PhotoAlbum
  ...
  defaultContainerWidth={300}
/>

内容的提问来源于stack exchange,提问作者Ashiq Dey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 21:42:04