Adblock detector for React
npm install detect-adblock-reactAdBlock detector for React. Live example - detect-adblock-react.ivanadmaers.com
- ✅ Ease of use
- 🔧 Well-tested
- 📦 Lightweight
- 📝 MIT license
- 🎉 NextJS, GatsbyJS and RemixJS support
``bashVia npm:
npm i detect-adblock-react
Usage
`jsx
import React from 'react';
import { useDetectAdblock } from 'detect-adblock-react';const App = () => {
const { adBlockDetected } = useDetectAdblock();
return (
{adBlockDetected === null && Defining…
}
{adBlockDetected === false && AdBlock was not detected
}
{adBlockDetected === true && AdBlock was detected
}
);
};export default App;
`Hook returns
adBlockDetected - was AdBlock detected or not. Null only when defining for the first time - null | boolean
detect - call this function if you need to check AdBlock one more time - function
`jsx
const { adBlockDetected, detect } = useDetectAdblock();useEffect(() => {
setTimeout(() => {
// Check AdBlock again after time
detect();
}, 5 * 1000);
}, []);
`Local development
1. Clone the project
2. Run
`bash
npm ci inpm start
`The last command runs webpack to compile our package to a dist folder
3. cd example/
4. Run
`bash
npm ci inpm start
``The last command runs webpack dev server
5. Enjoy the magic!
Copyright (c) 2022-present, Ivan Admaers