Set cookie value before handling side-effects (#76)

This commit is contained in:
Bram Devries 2020-06-28 11:26:06 +02:00 committed by GitHub
parent 8561858333
commit 4fa6476406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### changed
- Set cookie value before handling side-effects.
## [5.1.0]
A new feature! This time it's an "overlay" on the entire website to block access whilst the cookiebar is displayed.

View File

@ -118,14 +118,14 @@ class CookieConsent extends Component {
accept({ acceptedByScrolling = false }) {
const { cookieName, cookieValue, hideOnAccept, onAccept } = this.props;
this.setCookie(cookieName, cookieValue);
// fire onAccept
onAccept({ acceptedByScrolling });
// remove listener if set
window.removeEventListener("scroll", this.handleScroll);
this.setCookie(cookieName, cookieValue);
if (hideOnAccept) {
this.setState({ visible: false });
}
@ -145,16 +145,16 @@ class CookieConsent extends Component {
setDeclineCookie,
} = this.props;
if (setDeclineCookie) {
this.setCookie(cookieName, declineCookieValue);
}
// fire onDecline
onDecline();
// remove listener if set
window.removeEventListener("scroll", this.handleScroll);
if (setDeclineCookie) {
this.setCookie(cookieName, declineCookieValue);
}
if (hideOnDecline) {
this.setState({ visible: false });
}