I have installed @ionic-native/core.
But I am unable to use the contacts plugin in Ionic with react. ‘@ionic-native/contacts’
let contact: Contact = this.contacts.create();
and it’s showing me error:
Property ‘create’ does not exist on type ‘typeof Contacts’
Note- I’m using Capacitor
npm install cordova-plugin-contacts
npm install @ionic-native/contacts
Help me .
Thanks in Advance,
I think you’ll need to create an instance of the Contacts
class first
import { Contacts } from '@ionic-native/contacts';
const contacts = new Contacts();
//...
const contact = contacts.create();
I’m using react use, Function base component
Yeah, so use the contacts
instance inside your component function.
Could you help me out with syntex, Thanks in Advance
I gave you an example above. Just use the contacts
where you need it inside your React component, wherever you need it. I don’t know exactly when you want to call contacts.create
, if it’s when the user clicks a button it will be something like
import { Contacts } from '@ionic-native/contacts';
const contacts = new Contacts();
const SomePage = () => {
const handleClick = () => {
const contact = contacts.create();
// ...
};
// ...
return (
{/*...*/}
<IonButton onClick={handleClick} />
{/*...*/}
);
};