我试图把一些数据从反应到Javascript。如何将它们传递给window对象或从窗口访问React状态?我们的分析代码(无反应)需要能够访问React中的一些数据。
<Helmet>
<script type="text/javascript" >
var userId = 'user_123456789' // This works
var userId = {userId} // This doesn't work
</script>
<script src={withPrefix('analytics')} type="text/javascript" />
</Helmet>错误
TypeError: tag[primaryAttributeKey].toLowerCase is not a function
(anonymous function)
node_modules/react-helmet/es/Helmet.js:253
250 | return false;
251 | }
252 |
> 253 | var value = tag[primaryAttributeKey].toLowerCase();
254 |
255 | if (!approvedSeenTags[primaryAttributeKey]) {
256 | approvedSeenTags[primaryAttributeKey] = {};发布于 2022-11-07 19:19:23
对于任何想知道答案的人,我都是这样做的:
const Element = () => {
return (
<Helmet>
<script>
lol = window.url
</script>`
</Helmet>
)
}
useEffect(() => {
window.url = 'https://what.com';
}, [])https://stackoverflow.com/questions/65312772
复制相似问题