[英]RSS doesn't render in React component
I am trying to display a RSS widget on my website and I am trying to render it from my React component. 我试图在我的网站上显示一个RSS小部件,并且试图从我的React组件渲染它。 But it doesn't show up. 但是它没有出现。 When I tried to add it to my HTML file, at the bottom of it works perfect. 当我尝试将其添加到我的HTML文件时,它的底部运行良好。
How should I go about adding script tags to React? 我应该如何向React添加脚本标签?
This is my component: 这是我的组件:
import React, { Component } from 'react';
class Blog extends Component {
render() {
return (
<div className="container">
<h1 className="page-header">Blog</h1>
<script type="text/javascript" src="https://feed.mikle.com/js/fw-loader.js" data-fw-param="52132/"></script>
</div>
);
}
}
export default Blog;
You might try loading the <script>
outside of your render
method and moving it into a lifecycle method instead - that is, unless you want the script to load every time the render
method gets called. 您可以尝试将<script>
加载到render
方法之外,然后将其移至生命周期方法中-也就是说,除非您希望脚本在每次调用render
方法时都加载。 Try something like this: 尝试这样的事情:
componentWillMount() {
const script = document.createElement("script");
script.src = "https://use.typekit.net/foobar.js";
// you may want to load the script asynchronously so that is is
// only executed once available
script.async = true;
document.body.appendChild(script);
}
This way, your <script>
should get called just before your component mounts. 这样,您的<script>
应该在组件安装之前被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.