I’ve implemented Tawk in a React application, using the @tawk.to/tawk-messenger-react
library. It works fine but there are errors in the console:
Uncaught TypeError: e.onBeforeLoad is not a function
Uncaught TypeError: e.onStatusChange is not a function
These point to:
window.addEventListener("tawkStatusChange", t => {
e.onStatusChange(t.detail)
}
),
window.addEventListener("tawkBeforeLoad", () => {
e.onBeforeLoad()
}
Perhaps a bug in the library?
1 Like
HI changeroo,
If the Tawk APIs are emitting/calling the function you added inside of the callback seems the API is working fine. Where did you get the e
? is it a variable that exists in your code file?
1 Like
I’m not sure @jaoaustero , but it turns out there are two ways I can solve the errors:
-
Downgrade from React 19 to React 18.
-
Add onBeforeLoad={() => {}}
:
return (
<TawkMessengerReact
propertyId="***"
widgetId="***"
ref={tawkMessengerRef}
onLoad={onLoad}
onBeforeLoad={() => {}}
onStatusChange={() => {}}
/>
);
I think the library might have a compatibility issue with the latest React version. In React 19 the library no longer seems to fall back to its default props.