问题描述
我在javascript / components / cardlist /文件夹中包含以下两个组件,该组件正尝试在Rails 5.1.7的erb视图中呈现
CardList.js
import React from "react"
import PropTypes from "prop-types"
import CardBlock from './CardBlock'
class CardList extends React.Component {
render () {
const allCards = this.props.all_cards.map((card,index) => (
<CardBlock
key={card.id}
name={card.card_name}
/>
));
return (
<React.Fragment>
{allCards}
</React.Fragment>
);
}
}
CardList.propTypes = {
all_cards: PropTypes.array
};
export default CardList
在同一文件夹中有卡片块,外观如下:
CardBlock.js
import React from "react"
import PropTypes from "prop-types"
class CardBlock extends React.Component {
render () {
return (
<React.Fragment>
<p>trial</p>
</React.Fragment>
);
}
}
CardList.propTypes = {
listing_name: PropTypes.string
};
export default CardBlock
我有意见
<%= react_component("cardlist/cardlist",{ all_cards: @all_cards },{prerender: true}) %>
CardList组件中的行import CardBlock from './CardBlock'
给了我这个错误:
Encountered error "#<ExecJS::ProgramError: Error: 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.>" when prerendering cardlist/CardList with
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)