react-grid-system icon indicating copy to clipboard operation
react-grid-system copied to clipboard

Usage with Gatsby

Open radenkovic opened this issue 3 years ago • 2 comments

Hi folks, this is very nice library for doing grid!

Just wanted to help to other people who are trying to set up with gatsby:

To add custom configuration you need 2 files:

  1. gatsby-browser.js
import { setConfiguration } from 'react-grid-system';
// Here we configure grid
setConfiguration({ maxScreenClass: 'xl', defaultScreenClass: 'xl' });
  1. gatsby-ssr.js
const { setConfiguration } = require('react-grid-system');

exports.onPreRenderHTML = () => {
  // Here we configure grid
  setConfiguration({ maxScreenClass: 'xl', defaultScreenClass: 'xl' });
};
  1. Also you need to wrap all components in <ScreenClassProvider /> so pages look exactly the same and layout does not get re-rendered after initial hydration.

I think this can be documented in examples or in README.md but took me some time to set it up.

If there are any questions feel free to ask!

radenkovic avatar Mar 26 '21 16:03 radenkovic

I'm looking to a similar solution for NextJS. I guess we have the same issue here.

sephi-dev avatar May 03 '21 22:05 sephi-dev

@davidvenin same solution should technically work for NextJS (though I did not test). in getInitialProps do the same thing as I did in gatsby-ssr.js and it should do the trick.

radenkovic avatar May 04 '21 09:05 radenkovic