导入未定义的React组件

时间:2019-02-12 09:17:48

标签: javascript node.js reactjs

我有以下两种方法来声明名为DashboardComponent的React组件。

export default function DashboardComponent() {
    return <div>test</div>
}

export default class DashboardComponent extends React.Component {
    render() {
        return <div>test</div>
    }
}

当测试这两个时,我评论了另一个。

问题是,当我用

测试时
import DashboardComponent from './main/dashboard-component';
console.log(DashboardComponent);

第一个返回function,第二个返回undefined。为什么会这样?

1 个答案:

答案 0 :(得分:0)

问题是我有循环依赖。

我有一个包含路线的文件,在这里我正在导入@app.route("/", methods=['GET','POST']) def webhook(): state = session.get('state') session.modified = True print("state:",state) q_number = session.get('q_number') age = session.get('age') print('age:',age) sex = session.get('sex') symptoms = session.get('symptoms', []) prev = session.get('prev') conditions = session.get('conditions') data = request.get_json() ##pprint(data["entry"]) sender_id = data["entry"][0]["messaging"][0]["sender"]["id"] # get user info r = requests.get('https://graph.facebook.com/v3.1/'+sender_id+ '?fields=first_name,last_name&access_token='+ACCESS_TOKEN) if data["object"] == "page": user_input = data['entry'][0]['messaging'][0]['message']['text'] #print(type(user_input)) user_input = user_input.lower() #print(user_input) question = get_question(sender_id,user_input,state, q_number, age, sex, symptoms, prev, conditions) send_message(sender_id, question) return "ok", 200

DashboardComponent

我还在import DashboardComponent from './main/dashboard-component'; const routes = [ { label: 'Dashboard', path: "/", exact: true, component: DashboardComponent, icon: 'home' }, ... ] 中包含了路由文件。这是从我以前的测试中得出的。删除从DashboardComponent导入的路由可以解决此问题。