在React-Native
中我得到了错误,因为:
Invariant violation: View config not found for name MyCustomComponent.
我确实搜索了相同的错误,并发现组件名称的第一个字符应该大写,就在我的例子中。
这就是我要做的:我尝试使用名称来加载组件,而不是直接使用<MyCustomComponent />
来呈现它。
这是我的代码:
<View style={{ backgroundColor: 'yellow' }} >
{React.createElement('MyCustomComponent', {}, null)}
</View>
这里有什么问题。还有其他方法可以使用字符串加载组件吗?
发布于 2018-04-11 23:24:02
您需要将component
而不是string
传递给方法。
喜欢
{React.createElement(MyCustomComponent, {}, null)}
而不是
{React.createElement('MyCustomComponent', {}, null)}
字符串只适用于tags
https://stackoverflow.com/questions/49789869
复制相似问题