63
loading...
This website collects cookies to deliver better user experience
npx create-react-app react-onesignal
cd react-onesignal
npm start
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "YOUR-APP-ID",
});
});
</script>
window.OneSignal = window.OneSignal || [];
const OneSignal = window.OneSignal;
window
object aware of the OneSignal
property. This will allow you to have access to the OneSignal SDK properties after the SDK has loaded into your web application.useEffect
. This hook will have the initialization code needed to trigger OneSignal. Remember to add the dependency array []
to your useEffect
hook. The init()
method from OneSignal can only be called once and the dependency array will help us to avoid that the useEffect gets triggered multiple times firing the init()
method.useEffect(() => {
OneSignal.push(() => {
OneSignal.init({
appId: "YOUR-APP-ID"
})
});
},[]);
OneSignal
variable to different components. You can also use the custom code setup to modify the configurations of your prompt inside of your ReactJS application without using the OneSignal dashboard. To learn more about our Web Push SDK, visit our web pushSDK documentation.