I have a Gatsby site and I'm implementing a GDPR consent banner. I want to store state in local storage containing a "true" or "false" string pertaining to if the user has accepted the GDPR terms.
For example, a user shows up to the site for the first time. In local storage there is a "GDPR_Accepted" key that is set to "false". If the user doesn't accept the GDPR terms on the home page the banner will continue to be displayed on every page the user visits. When the user clicks accept the GDPR_Accepted value is set to "true", and a ternary operator in my React component applies a CSS class that hides the banner.
Because I'm using local storage the "true" value should persist even if the user leaves the page and returns later (assuming they don't clear their browsing history). The problem is with Gatsby. Gatsby uses server side rendering and when the user accepts the GDPR terms and leaves the website and comes back, the GDPR value is reset to "false". Gatsby is unable to persist the local storage data from earlier when it was set to "true".
How can I persist data in local storage in a Gatsby project? Would it make more sense to just use React state to store whether or not the user has accepted the GDPR terms?