Incompatible with SSR
Related to https://github.com/livechat/react-livechat/issues/19 This component is using componentWillMount hook which is a) deprecated and b) apparently called in Next.js server-side rendering
Switching to componentDidMount would fix this in my understanding. I can send a PR but this repo doesn't have the rollup config file so I cannot test the builds when iterating on the code.
If you'd publish your rollup.config.js and maybe other dev-related stuff I'd send a PR myself.
Just figured I have the same problem here
this worked for me
import React from 'react';
import LiveChat from 'react-livechat'
export default class LiveChatApi extends React.Component {
render() {
if (typeof window === 'undefined') return null;
return (
<LiveChat license={11794446} />
);
}
}
Yes, of course, there are workarounds. Still, this component could (and should) be improved if only LC didn't forget about this repo.
BTW, your code can be even shortened:
import React from 'react';
import LiveChat from 'react-livechat';
export default const LiveChatApi = (props) =>
typeof window !== 'undefined' && <LiveChat {...props} />
Hello 👋
We didn't forget fortunately 😅 I am happy to say that we have created a new set of packages to support more frontend frameworks integration with LiveChat Chat Widget: Chat Widget Adapters.
After the first main implementation, we are planning to introduce support for SSR and SSG. You can feel free to open feature request or send us an issue report 🙂