Compatible with Create React App, Vite, and React Router.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Your App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<!-- tokwork Widget -->
<script async src="https://js.tokwork.com/loader.js"
data-website-id="YOUR_WEBSITE_ID"
data-website-domain="yourdomain.com">
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!-- tokwork Widget -->
<script async src="https://js.tokwork.com/loader.js"
data-website-id="YOUR_WEBSITE_ID"
data-website-domain="yourdomain.com">
</script>
</body>
</html>
Create a custom hook for more control:
import { useEffect } from 'react'
export function useTokwork(websiteId: string, domain: string) {
useEffect(() => {
// Check if script already loaded
if (document.querySelector('[data-tokwork-script]')) {
return
}
const script = document.createElement('script')
script.src = 'https://js.tokwork.com/loader.js'
script.async = true
script.setAttribute('data-website-id', websiteId)
script.setAttribute('data-website-domain', domain)
script.setAttribute('data-tokwork-script', 'true')
document.body.appendChild(script)
return () => {
// Cleanup if needed
const existingScript = document.querySelector('[data-tokwork-script]')
if (existingScript) {
existingScript.remove()
}
}
}, [websiteId, domain])
}
Use in your App component:
import { useTokwork } from './hooks/useTokwork'
function App() {
useTokwork('YOUR_WEBSITE_ID', 'yourdomain.com')
return (
<div className="App">
{/* Your app content */}
</div>
)
}
export default App
Use .env files for configuration:
REACT_APP_TOKWORK_WEBSITE_ID=your-website-id
REACT_APP_TOKWORK_DOMAIN=yourdomain.com
Then use them:
useTokwork(
process.env.REACT_APP_TOKWORK_WEBSITE_ID!,
process.env.REACT_APP_TOKWORK_DOMAIN!
)
Works seamlessly with React Router. Add to your root component:
import { BrowserRouter } from 'react-router-dom'
import { useTokwork } from './hooks/useTokwork'
function App() {
useTokwork('YOUR_WEBSITE_ID', 'yourdomain.com')
return (
<BrowserRouter>
{/* Your routes */}
</BrowserRouter>
)
}
Add type definitions:
declare global {
interface Window {
WOM_WIDGET_CONFIG?: Array<{
websiteId: string
backendUrl?: string
}>
}
}
export {}
npm start or npm run dev✅ tokwork Widget loaded successfullyThis is normal in React Strict Mode during development. Use the data-tokwork-script attribute check to prevent duplicates.
The widget should persist across routes. Check console for errors.