mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-01-20 18:41:44 +01:00
Set cookie value before handling side-effects (#76)
This commit is contained in:
parent
8561858333
commit
4fa6476406
@ -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/),
|
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).
|
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]
|
## [5.1.0]
|
||||||
|
|
||||||
A new feature! This time it's an "overlay" on the entire website to block access whilst the cookiebar is displayed.
|
A new feature! This time it's an "overlay" on the entire website to block access whilst the cookiebar is displayed.
|
||||||
|
14
src/index.js
14
src/index.js
@ -117,6 +117,8 @@ class CookieConsent extends Component {
|
|||||||
*/
|
*/
|
||||||
accept({ acceptedByScrolling = false }) {
|
accept({ acceptedByScrolling = false }) {
|
||||||
const { cookieName, cookieValue, hideOnAccept, onAccept } = this.props;
|
const { cookieName, cookieValue, hideOnAccept, onAccept } = this.props;
|
||||||
|
|
||||||
|
this.setCookie(cookieName, cookieValue);
|
||||||
|
|
||||||
// fire onAccept
|
// fire onAccept
|
||||||
onAccept({ acceptedByScrolling });
|
onAccept({ acceptedByScrolling });
|
||||||
@ -124,8 +126,6 @@ class CookieConsent extends Component {
|
|||||||
// remove listener if set
|
// remove listener if set
|
||||||
window.removeEventListener("scroll", this.handleScroll);
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
|
|
||||||
this.setCookie(cookieName, cookieValue);
|
|
||||||
|
|
||||||
if (hideOnAccept) {
|
if (hideOnAccept) {
|
||||||
this.setState({ visible: false });
|
this.setState({ visible: false });
|
||||||
}
|
}
|
||||||
@ -144,17 +144,17 @@ class CookieConsent extends Component {
|
|||||||
extraCookieOptions,
|
extraCookieOptions,
|
||||||
setDeclineCookie,
|
setDeclineCookie,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
if (setDeclineCookie) {
|
||||||
|
this.setCookie(cookieName, declineCookieValue);
|
||||||
|
}
|
||||||
|
|
||||||
// fire onDecline
|
// fire onDecline
|
||||||
onDecline();
|
onDecline();
|
||||||
|
|
||||||
// remove listener if set
|
// remove listener if set
|
||||||
window.removeEventListener("scroll", this.handleScroll);
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
|
|
||||||
if (setDeclineCookie) {
|
|
||||||
this.setCookie(cookieName, declineCookieValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hideOnDecline) {
|
if (hideOnDecline) {
|
||||||
this.setState({ visible: false });
|
this.setState({ visible: false });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user