Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
react-gdpr-guard
Advanced tools
Official React binding for gdpr-guard
react-gdpr-guard
acts like a meta-hook library: it exposes a single hook that you can use outside of your React app
to create hooks that you will later use in that react app.
You must know about the gdpr-guard
library and how it works.
Here are a few links to get up to speed:
In a separate file, let's say a hooks/gdpr.js
for instance, you can create your hooks alongside your GdprSavior
and manager factory:
// src/hooks/gdpr.js
const managerFactory = () => {
return GdprManagerBuilder.make()
/* [...] */
.build();
};
const savior = new MyGdprSavior();
export const {
useSetupGdprEffect,
useAttachGdprListenersEffect,
useGdprManager,
useGdprSavior,
useGdpr,
useGdprComputed,
useGdprGuard,
useGdprGuardEnabledState,
} = createGdprGuardHooks(savior, managerFactory);
Then, in your main component, you can attach the setup hook and the listeners hook:
// src/App.jsx
import {
useSetupGdprEffect,
useAttachGdprListenersEffect,
useGdpr,
} from "./hooks/gdpr.js";
import MyGdprBanner from "./components/MyGdprBanner";
import MyGdprSettingsOpener from "./components/MyGdprSettingsOpener";
export default function App() {
const {
bannerWasShown,
closeGdprBanner,
resetAndShowBanner,
} = useGdpr();
// Bootstrap the library
useSetupGdprEffect();
// Attach events
useAttachGdprListenersEffect(eventHub => {
eventHub.onEnable("_ga", () => {
// Load all Analytics scripts here
});
eventHub.onDisable("myIntrusive3rdPartyStuff", () => {
// Disable everything from the intrusive 3rd-party lib
});
});
// The rest of your component logic
return (
<>
<MyGdprSettingsOpener onClick={resetAndShowBanner}/>
{!bannerWasShown && <MyGdprBanner onClose={closeGdprBanner} />}
{/* The rest of your component's UI */}
</>
);
}
Default values must be chosen carefully and with the user's experience in mind. For instance: if geolocation is optional, disable it by default.
After the user changes their settings, saving them using the Savior API is recommended.
A tiny button or link that, when clicked, calls the resetAndShowBanner
so that the GDPR settings UI may be opened again.
A banner, a modal or whatever prevents users from using your website without first interacting with it.
It should display at the very least 4 buttons:
enableManager
and then closeBanner
disableManager
and then closeBanner
closeBanner
Generally a modal (but can be whatever) in which the user has access to the following:
toggleManager
enableManager
and then closeBanner
disableManager
and then closeBanner
closeBanner
The meta-hook that creates hooks, based on your manager and savior, that you can use throughout your app.
useSetupGdprEffect
is a simple hook that just bootstrap the whole library's core logic.
As such, you must use it (preferably only in one place) within your app. To keep things simple
and organized, you might want to call it within your App
component.
It behaves exactly like useMemo
but recomputes its value upon changes within the GDPR manager.
Gives you direct access to the wrapper around the GdprSavior
instance you provided. This may not be needed, but is
useful if you need to tap into the lifecycle of your GDPR manager.
Gives you direct access to the wrapper around the GdprManager
instance that is restored using the provided GdprSavior
.
It allows you to query and mutate your manager's state directly even though there are different hooks for that exact purpose.
It allows you to attach events listeners to your manager's GdprManagerEventHub
.
This is where you'll listen for enable/disable events on particular guards.
It allows you to query the enabled state of the guard that has the given guardName
.
If useBannerStatus
, and for the enable state to be true, the banner would have to have been shown to the user.
It allows you to control a single guard and access its data:
const {
guard, // instance of GdprGuardRaw
enableGuard, // callback to enable that guard
disableGuard, // callback to disable that guard
toggleGuard, // callback to toggle that guard
} = useGdprGuard("My guard's name");
Note that this also applies to GdprGroup
s since they are also GdprGuard
s.
It allows you to do and access a lot of things at once, so let's detail those:
const {
bannerWasShown,
manager,
closeGdprBanner,
resetAndShowBanner,
enableManager,
disableManager,
toggleManager,
enableGuard,
disableGuard,
toggleGuard,
guardIsEnabled,
enableForStorage,
disableForStorage,
toggleForStorage,
} = useGdpr();
Direct access to whether the GDPR banner has been shown or not (useful for conditional rendering of the banner itself).
Direct access to the current state of the manager as a GdprManagerRaw
instance.
Useful to manually query the state or help build the UI.
When called will close the GDPR banner and call the appropriate event listeners.
When called will reset the shown status of the GDPR banner.
When called will enable every guard within the manager (except required ones). Useful for the "Accept All" button of the GDPR banner.
When called will disable every guard within the manager (except required ones). Useful for the "Reject All" button of the GDPR banner.
Toggle the enabled/disabled state of the manager and sets every guard to that state. Useful to have a global switch on the GDPR settings UI.
Enable the guard that has the given name. Also works for groups of guards. Can be useful when building the GDPR settings UI.
Disable the guard that has the given name. Also works for groups of guards. Can be useful when building the GDPR settings UI.
Toggle the guard that has the given name. Also works for groups of guards. Can be useful when building the GDPR settings UI.
Query the enabled state of the given guard. When using the banner status, the guard can only be considered if the banner has already been shown.
Enable guards that are stored in the given GdprStorage
.
Can be useful when building the GDPR settings UI.
Disable guards that are stored in the given GdprStorage
.
Can be useful when building the GDPR settings UI.
Toggle guards that are stored in the given GdprStorage
.
Can be useful when building the GDPR settings UI.
Add manager hotswap on boot
Fix library build
Initial release
FAQs
Official React binding for gdpr-guard
We found that react-gdpr-guard demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.