import React from "react";
import LoadScript from "react-load-script";
function Addthis() {
return (
<LoadScript url="http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-xxxx" />
);
}
export default Addthis;
到目前为止,这是我用来初始化addthis的代码。我在GitHub上发现了此问题,但尚未找到解决方案:https://gist.github.com/jonathanconway/9925286
答案 0 :(得分:0)
使用类似这样的内容:
import React from "react";
import ReactDOM from "react-dom";
import LoadScript from "react-load-script";
import "./styles.css";
function Addthis() {
const handleScriptLoad=()=>{
window.addthis.init();
window.addthis.toolbox('.addthis_toolbox')
console.log("addthis Loaded");
}
return (
<div>
<LoadScript
url="https://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-xxxx"
onLoad={handleScriptLoad}
/>
<div class="addthis_toolbox addthis_default_style " style={{margin: "20px"}}>
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<hr/>
</div>
);
}
function App() {
return (
<div className="App">
<Addthis />
<h1>Hello addthis</h1>
<h2>Buttons loaded (upper, left) of screen</h2>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
查看答案输出:HERE