【发布时间】:2019-07-27 20:48:37
【问题描述】:
我遇到了一个奇怪的 React/Storybook 错误。
我看到的错误是:
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.
这是导致错误的代码:
import React from 'react';
import styled from 'styled-components';
class LogoWordMark extends React.PureComponent {
static Container = styled.div``;
render() {
return (
<LogoWordMark.Container>
mnkladjkl asdjklas djkkjlsad jklasdjklasd kl
<a>asdad</a>
</LogoWordMark.Container>
);
}
}
export default LogoWordMark;
奇怪的是,如果我更新一行:
<a onClick={this.blah}>asdad</a>
然后组件按预期呈现。即使this.blah 没有定义。有人知道这里发生了什么吗?
我正在使用:
"react": "16.8.6",
"@storybook/react": "5.1.7",
【问题讨论】:
-
尝试用
div或>(反应片段)包装内容 -
环绕容器?还是里面?我都试过了,没有变化
-
我的意思是
<>mnkladjkl asdjklas djkkjlsad jklasdjklasd kl <a>asdad</a></> -
没有改变......有这个想法。仍然出错
-
This component works fine. 有其他错误。在那个锚点上弄乱一个道具应该没关系 - 您是否尝试过使用您正在使用的任何构建工具进行重建(以防它只是处于混乱状态)?