reactjs - CXJS 组件作为本机反应组件的子级
问题描述
我将 cxjs 中的许多功能组件与普通的 react 组件混合在一起。
但有时当我尝试使用 cxjs 组件作为反应组件的子组件时,我得到一个
"
error: 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.
"
我该如何解决这个问题?
非常感谢 !
Code which causes this problem:
CXJS component example, which works within cxjs as a child but causes error in react as a child:
import { Chart, Gridlines, NumericAxis } from 'cx/charts';
import { Rectangle, Svg } from 'cx/svg';
import {Controller} from "cx/ui";
export class Dcc extends Controller {
onInit(){
alert("Demochart initialised");
}
}
export default <cx>
<div class="widgets" controller = {Dcc}>
tiomo test
<Svg style="width:300px;height:200px" margin="10 20 30 50">
<Chart axes={{
x: <NumericAxis />,
y: <NumericAxis vertical/>
}}>
<Rectangle fill="white" />
<Gridlines />
</Chart>
</Svg>
timo
</div>
</cx>
现在是一个反应网格组件,可以与它一起使用: - 我可以随心所欲地添加反应子级。但没有像上面那样的 cxjs。
import React from 'react';
import { VDOM } from "cx-react";
import { findDOMNode } from "react-dom";
import GridLayout from 'react-grid-layout';
import "./index.scss";
import Demochart from "../../demochart";
export default class MyGrid extends React.Component {
render() {
return (
<GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
<div key="g" data-grid={{x: 14, y: 5, w: 6, h: 6}}><Demochart/></div>
</GridLayout>
)
}
}
解决方案
Cx
为了在 React 组件中使用 CxJS 小部件,需要 wrapper。
<MyReactComponent>
<Cx store={myCxStore} subscribe>
<Grid ... />
</Cx>
</MyReactComponent>
CxJS 组件不能在没有 store 的情况下工作,所以你必须通过一个。
在 CxJS 中使用 React 组件更为常见。
<cx>
<div>
<MyReactComponent />
</div>
</cx>
推荐阅读
- c# - Avalonia 组合框装订
- java - Azure Spring Boot 功能 - 如何同时将触发器和输入绑定都传递给 handleRequest 方法?
- angular - 从 NgRx Select 内部返回值
- php - Laravel“至少和最多”一个字段是必需的
- google-play - 了解订单簿的彩条
- python-3.x - 在计算器 Django 中集成多选项下拉列表
- html - Flask WTForms SelectField 添加占位符或禁用选项
- reactjs - 连接失败:套接字 io 中的资源不足错误
- jmeter - jmeter中的文件验证API失败
- artificial-intelligence - 如何适应 GOAP AI 模型中“目标”的变化?