这是 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 中添加。
关于javascript - 如何让这个 React 方法返回语句/变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56023523/