【发布时间】:2020-02-01 20:58:07
【问题描述】:
我正在尝试显示加载栏,直到它被获取。所以我选择使用材质UI加载栏。我创建了这个方法来显示加载栏 renderProgressBar。 但是当我试图渲染它时出现了这个错误:
invariant.js:42 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
我尝试在控制台中进行调试,但没有任何帮助。 您能告诉我如何使用下面的代码 sn-p 来修复它吗?
https://codesandbox.io/s/redux-async-actions-hntd8
renderProgressBar = () => {
console.log(
'store.getState().fetchingMessage---->',
store.getState().fetchingMessage
);
if (store.getState().fetchingMessage) {
console.log(
'inside if rstore.getState().fetchingMessage---->',
store.getState().fetchingMessage
);
return (
<div
>
<LinearProgress />
</div>
);
}
};
【问题讨论】:
-
如果您的 if 语句评估
false,您不会返回任何内容 -
如何导入 LinearProgress?看起来这可能是问题所在,AS @chautelly 说你的 if 语句正在重新调整 undefined
-
正如其他人所提到的,您的 LinearProgress 似乎没有正确导入。 material-ui.com/api/linear-progress
标签: javascript html css reactjs redux