Antonello Gatto
Antonello Gatto

Reputation: 1611

Initialize OneSignal SDK on Ionic with React.js

I'm trying to start with OneSignal SDK on a Ionic with React app, but I can't find any guide for React, all I find is for angular and I'm not pratice of typescript.

Where do I need to initialize OneSignal SDK?

I'm trying to do it in the App.componentDidMount such as:

componentDidMount() {
    this.props.oneSignal.startInit(
        "XXXXXX-XXX-XXX-X-XXXXX",
        "YYYYYYYYYY"
    );

    this.props.oneSignal.inFocusDisplaying(
        this.props.oneSignal.OSInFocusDisplayOption.InAppAlert
    );

    this.props.oneSignal.handleNotificationReceived().subscribe(() => {
        // do something when notification is received
    });

    this.props.oneSignal.handleNotificationOpened().subscribe(() => {
        // do something when a notification is opened
    });

    this.props.oneSignal.endInit();
}

but the IDE continues giving me errors about this.oneSignal does not exists in the type xxx.

Upvotes: 0

Views: 514

Answers (1)

Antonello Gatto
Antonello Gatto

Reputation: 1611

My fault. I was importing this way:

import { OneSignal } from '@ionic-native/onesignal/ngx';

This the correct way for React.js:

import { OneSignal } from '@ionic-native/onesignal';

Upvotes: 1

Related Questions