我正在开发一个 React 组件,我发现了一个特定的 javascript 代码可以修改我的 html 页面的内容。\n问题是我不知道如何将此脚本合并到我的组件中。我知道我可以用“import”语句调用它,但该脚本使用“window.onload”函数,该函数仅被调用一次,但我的组件被安装了多次,脚本将不再工作
\n\n组件 -
\n\nimport React, { Component } from \'react\';\nimport textRotation from \'../../scripts/textRotation\';\nimport \'./Main.scss\';\n\n\nclass Main extends Component {\n constructor(props) {\n super(props);\n this.title = props.title;\n this.imgSrc = props.imgSrc;\n }\n\n render() {\n return (\n <div className="Main">\n <div className="main-content">\n <div className="presentation-caption">\n <span>Hello, I\'m Jordan, a junior front-end developer, who does a lot of things.</span>\n </div>\n <div className="description-caption">\n <span>Prepare you to encounter various types of projects... but it\'s ok, just explore !</span>\n </div>\n <div className="button-container">\n <a href="#works"><button>Scroll …Run Code Online (Sandbox Code Playgroud)