javascript - 如何让这个 React 方法返回语句/变量?

标签 javascript html reactjs

这是 JobInfoPage.js 文件的片段,

import findMonthsTillSession from '../components/utility.js';

class JobInfoPage extends Component {
    render() {
            <div>The nearest hiring session is in: { findMonthsTillSession() } See you then!</div>
    }
}

我收到此错误: 尝试导入错误:“../components/utility.js”不包含默认导出(导入为“findMonthsTillSession”)。

最佳答案

您的问题中有 2 个错误,
(1) No return() in JobInfoPage.js文件
(2) Function is not imported with function name.
JobInfoPage.js

import findMonthsTillSession from '../components/utility.js';

class JobInfoPage extends Component {
    render() {
       return(
       <div>
            The nearest hiring session is in: { findMonthsTillSession() } See you then!
       </div>
       )
    }
}

添加import React from 'react';如果您还没有添加,请在 Utility.js 中添加。

另请阅读hackernoon export import cheatsheet .

关于javascript - 如何让这个 React 方法返回语句/变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56023523/

相关文章:

reactjs - 如何使用 React 和 Material-UI 嵌入 Calendly anchor 标记

javascript - jQuery mouseenter 函数 - 如果颜色还没有改变颜色

javascript - IDEA + Grunt - 如何实时编辑 JavaScript

javascript - jQuery 搜索表单 - 如何定向到内部页面

html - 菜单将内容推送到页面底部

reactjs - Ant 设计 : input validation with Forms

javascript - 使 rails 中的 javascript 库保持最新的最佳方法是什么?

javascript - Ember.js 不更新模型

javascript - HTML 如何自动创建/以编程方式创建 div?

reactjs - 使用 Om 有条件地将类添加到元素