I am using react native. I need to define a class:
class myClass {
email: string;
name: string;
constructor() {
setUser(fbid: string, token: string): boolean {
I am trying to define it in its own file myClass.js and when I include it in my index.ios.js , I get this error:
Can't find variable: myClass
Can you please point me to any documentation on how to define non react classes and use them in react native ? Thank you for reading.
You need to export classes you define.
example:
//myClass.js
export default class myClass {
email: string;
name: string;
constructor() {
//...
}
}
//index.ios.js
import myClass from './path/to/myClass.js'
Note the "export default", so you can define any class including non-react classes in a React Native (or Javascript es6) project and export it, making it available for import and use by other classes.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With