buildo / react-cookie-banner

React Cookie banner which can be automatically dismissed with a scroll. Because fuck The Cookie Law, that's why.
http://react-components.buildo.io/#cookiebanner
MIT License
182 stars 19 forks source link

Using this libray with DotNetCore ASP.NET #C React Redux #47

Closed adomrockie closed 6 years ago

adomrockie commented 6 years ago

It took me sometime to figure out how to use this with SSR for our project, hopefully it goes to show someone.

  1. For your component with cookies defined you only need to import CookieBannerUniversal. Use as below <CookieBannerUniversal {...props} > {this.props.children} </

  2. In your Client.js

    
    ReactDOM.render(
        <Provider store={store}>
            <CookiesProvider>
                <ConnectedRouter history={history} location children={routes} />
            </CookiesProvider>
        </Provider>
        ,
        document.getElementById('app')
    );
3. Server.js or boot-server.js

const convertCookieToString = (cookieArray) => { //do something to convert your array to normalized string. //e.g "a=1;b=2" return arrayTostring }

const serverCookiesArray = array({'a': '1'}, {'b' : '2'} )

const cookies = new Cookies(convertCookieToString(serverCookiesArray)) const app = (

    );

const render = renderToString(app)


NOTE: Make sure your server cookies array matches that found using document.cookie