我有以下应用程序组件:-
import React, { useEffect } from "react";
import Home from "./pages/Home";
import About from "./pages/About";
function App() {
useEffect(() => {
var Tawk_API = Tawk_API || {},
Tawk_LoadStart = new Date();
(function () {
var s1 = document.createElement("script"),
s0 = document.getElementsByTagName("script")[0];
s1.async = true;
s1.src = "https://embed.tawk.to/5ab8d/default";
s1.charset = "UTF-8";
s1.setAttribute("crossorigin", "*");
s0.parentNode.insertBefore(s1, s0);
})();
Tawk_API.onLoad = function () {
console.log("chat loaded");
Tawk_API.setAttributes(
{
name: "Test Name",
email: "email@email.com",
hash: "hash value",
},
function (error) {}
);
};
}, []);
return (
<div>
<div className="container-fluid rtl">
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</div>
</div>
);
}
export default App;
我可以看到那个聊天小部件,但是当我开始聊天时,不要获得访问者指定的名称。
我如何在 reactjs 中使用 setAttributes?