patw0929 / react-smartbanner

Rewrite Smart App Banner in React.js.
https://patw0929.github.io/react-smartbanner/
MIT License
74 stars 56 forks source link

Server-Side Rendering #7

Closed gbrlsepulveda closed 7 years ago

gbrlsepulveda commented 8 years ago

Hello!

Based on #6, i had the same issue(window is not defined). I would like to know if have you plans to do SSR. I would like do prepare some PR. Could be a good idea?

patw0929 commented 8 years ago

Thanks for your comment. Actually I have tried to make it work on SSR, but I stuck on it. 😢 And, Sure, I think it could be a good idea to support SSR.

danielzlotnik commented 8 years ago

A quick and dirty solution could be:

const React = require('react');

if (typeof window !== 'undefined'){
    const ReactSmartbanner = require('react-smartbanner').default;
    module.exports = () => (<ReactSmartbanner title={'Your Title'} />);
}
else {
    module.exports = () => (<span/>);
}
mmahalwy commented 7 years ago

Similar to @danielzlotnik, the right solution is to move all your client side code into componentDidMount since that renders only on the client.