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.
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.
Share Improve this question asked Mar 4, 2016 at 19:47 JohnJohn 751 gold badge1 silver badge5 bronze badges 2 |1 Answer
Reset to default 20You 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.
Custom objects
section : developer.mozilla.org/en-US/docs/Web/JavaScript/… – Dany Khalife Commented Mar 4, 2016 at 19:59