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
2 changed files with 13 additions and 7 deletions

View File

@@ -117,6 +117,8 @@ class CookieConsent extends Component {
*/
accept({ acceptedByScrolling = false }) {
const { cookieName, cookieValue, hideOnAccept, onAccept } = this.props;
this.setCookie(cookieName, cookieValue);
// fire onAccept
onAccept({ acceptedByScrolling });
@@ -124,8 +126,6 @@ class CookieConsent extends Component {
// remove listener if set
window.removeEventListener("scroll", this.handleScroll);
this.setCookie(cookieName, cookieValue);
if (hideOnAccept) {
this.setState({ visible: false });
}
@@ -144,17 +144,17 @@ class CookieConsent extends Component {
extraCookieOptions,
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 });
}