0

I can't get this react class to export and I can't figure out why. I have the export class at the bottom and everything is extending what it should. Is it my withRouter method?

import React, {Component} from 'react';
import {HeaderAdmin} from '../headerAdmin';
import {DashBoxes} from './dashBoxes';
import {MetaData} from '../metaData';
import {withRouter} from 'react-router-dom';

class CoachDashMain extends Component {

    render() {
        return(
            <div>
                <HeaderAdmin />
                <DashBoxes />
                <MetaData />
            </div>
            );
    }
}

export default withRouter(CoachDashMain);

the error I'm getting is ./components/Coach/coachDashMain' does not contain an export named 'CoachDashMain'.

the import in another file looks like:

import {CoachDashMain} from './components/Coach/coachDashMain'

2 Answers2

3

You are using named imports: import { CoachDashMain } from '...', which gives the above error unless you have export class CoachDashMain ... in that file.

Since you are using export default ..., you should import it by:

import CoachDashMain from '...'; // `CoachDashMain` can be renamed to anything
Roy Wang
  • 11,112
  • 2
  • 21
  • 42
  • How can you know this if the OP hasn't even provided his import code statement - no matter how likely this might be - we should wait to get all the info before pasting possible answers. – Matthew Brent May 25 '18 at 14:20
  • @MatthewBrent based on the error message I couldn't think of any other possible causes. – Roy Wang May 25 '18 at 14:23
  • No - I know and more than likely that is the cause, my main reason for saying this is to help people to learn how to ask more detailed and better questions. The OPs question as it's currently written seems like a pretty knee-jerk response to an issue they have encountered. With little thought put into the question. – Matthew Brent May 25 '18 at 14:30
  • @MatthewBrent most people just didn't know what they need to provide. In this case, the error message happens to be sufficient to diagnose the problem accurately. Ideally, almost every question should come with a [mcve](https://stackoverflow.com/help/mcve)...Anyway, this is probably best discussed in meta. – Roy Wang May 25 '18 at 14:52
0

When you default export the class, you don't need the curly braces while importing that class in another file.

So, you should import like:

import CoachDashMain from './components/Coach/coachDashMain';
Hitesh Chaudhari
  • 705
  • 1
  • 7
  • 12