这是一个简化的 React 组件,它使用头盔在运行时更新链接 css:
function App() {
const [brand, setBrand] = useState('nike')
return (
<div className="App">
<Helmet>
<link rel="stylesheet" href={getBrandStyle(brand)} />
</Helmet>
<div>other contents here</div>
<!-- omitted the button components that change the brand state by calling setBrand -->
</div>
);
}
我最近刚刚使用 react-helmet 作为一种声明性方式来更改 head 标签的子标签,并且使用我上面编写的代码,在切换 css 时,当页面没有 css 样式时会出现瞬间延迟,然后 1 秒后更新的 css 显示向上。
即使在页面的初始加载期间,如果我使用 queryParameters (上面的代码没有显示查询参数方法),例如
https://localhost:3000?brandQueryParam=nike
在品牌 css 出现之前,有 1 秒钟没有 css 样式。
你能告诉我我缺少什么以及如何解决这个问题吗?