0

I am learning react native. i want to rewrite the following line using a plain javascript class.

module.exports = React.createClass({

to

export class Dashboard extends React.Component {

not sure if i am doing it right. in the original code, it just exports without giving a class name. can I do the same? or does it hurt if I give a name.

the full source code is there. the line i try to modify is line 19.

1 Answer 1

2

I depends on how you import the component. You are currently using named export so you need to import it by it's name - Dashboard:

export class Dashboard extends React.Component {

// and then import by name
import { Dashboard } from './myfile';
// or with require
var Dashboard = require('./myfile').Dashboard;

If you use default export you can name it however you like:

export default class Dashboard extends React.Component {

// and then import
import Dashboard from './myfile';
// or with custom name
import MyComponent from './myfile';
// or with require
var Dashboard = require('./myfile');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.