- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 React 中使用延迟加载。我已经从 React 中导入了惰性组件和 Suspense 组件。该页面不再显示任何内容。但我得到的错误是:
Expected the result of a dynamic import() call. Instead received: [object Object]. Element type is invalid. Received a promise that resolves to: undefined. Promise elements must resolve to a class or function.
这是 SibaCard 组件
export class SibaCard extends React.Component<ICardProps, ICardState> {
constructor(props: ICardProps) {
super(props);
this.state = {expanded: true};
}
expandChange = () => {
this.setState((prevState: any) => ({ expanded: !prevState.expanded }));
}
style = {
headerStyle: {
borderBottom: "2px solid #258ECB",
marginBottom: "1em",
background: "linear-gradient(rgba(0,0,0,0.0),rgba(0,0,0,0.02))"
},
containerStyle: {
}
}
render() {
return (
<Card
style={{ border: "1px solid rgba(0,0,0,0.1)",marginTop: "4.5em", boxShadow:"none" }}
expanded={this.state.expanded}
expandable={false}
containerStyle={this.style.containerStyle}
onExpandChange={this.expandChange.bind(this)}
>
<CardHeader
title={this.props.title}
subtitle={this.props.subTitle}
actAsExpander={false}
showExpandableButton={true}
style={this.style.headerStyle}
/>
<CardText expandable={true}>
{this.props.children}
</CardText>
</Card> );
}
}
这是我导入Sibacard的组件
import * as React from 'react';
const lazy = (React as any).lazy;
const Suspense =(React as any).Suspense ;
import { SingleSetup, ISingleSetupProps } from
"../../../Shared/Views/SingleSetup";
import { LovDropDown } from "../../../Shared/Views/FormComponents";
import { LoanRepaymentScheduleService } from
"../../Services/LoanRepaymentSchedule/LoanRepaymentScheduleService";
import { RaisedButton } from "material-ui/RaisedButton";
const SibaCard = lazy(() => import('../../../Shared/Views/SibaCard'));
export class LoanPayOff extends SingleSetup<ILoanRepaymentSchedule>{
loanrepaymentservice:LoanRepaymentScheduleService;
employeeservice:EmployeeService;
loantypeService:LoanTypeService;
constructor(props: ISingleSetupProps<ILoanRepaymentSchedule>){
super(props,{
id: 0,
employeeId: "",
principalAmt: 0,
},[
grid definition
],[
],
new LoanRepaymentScheduleService(),{
list: ""
});
this.formId = "loanrepayForm";
}
render() {
return (<div>
{this.actionMenu(false, true, false)}
<Suspense fallback={<div>Loading...</div>}>
<div className="" style={{ marginTop: "4.5em" }}>
<SibaCard
title="Employee Loan Pay Off Form"
subTitle="Enter details below">
<FormField>
<form id="loanrepayForm" className="row">
<div className="col-sm-4">
<LovDropDown
id="employeeId"
title="Employee"
label="Employee"
name="employeeId"
required={true}
value={this.state.model.employeeId}
onChange=
{this.fieldChange.bind(this)}
service=
{this.employeeservice.getLov.bind(this.employeeservice)}/>
<Input
label="Terms To Pay"
name="list"
type="number"
value = {this.state.props.list}
onChange=
{this.propChange.bind(this)} />
</div>
<div className="col-sm-4">
<LovDropDown
label="Loan Type"
title="Loan Type"
id="loanTypeCode"
name="loanTypeCode"
required={true}
value={this.state.model.loanTypeCode}
service={this.loantypeService.getLov.bind(this.loantypeService)}
onChange={this.fieldChange.bind(this)}
/>
</div>
<div className="col-sm-4">
<RaisedButton
icon={<FileFileDownload className="ico" color="#7ED321"/>}
backgroundColor="rgba(0,0,0,0.3)"
style={{ float: "none",paddingLeft:"4px",paddingRight:"4px" }}
label="Search"
onClick={this.LoadDetails.bind(this)}
/>
<RaisedButton
icon={<FileFileDownload className="ico" color="#7ED321"/>}
backgroundColor="rgba(0,0,0,0.3)"
style={{ float: "none",paddingLeft:"4px",paddingRight:"4px" }}
label="Pay Off"
onClick={this.PayOff.bind(this)}
/>
</div>
</form>
</FormField>
<div className="">
{this.MultiSelectGrid()}
</div>
</SibaCard>
</div>
{console.log(this.state.selectedRow.length)}
{console.log(this.state)}
{this.viewConstants()}
</Suspense>
</div>);
}
}
谁能告诉我我做错了什么?
最佳答案
docs声明:
React.lazy
takes a function that must call a dynamicimport()
. This must return aPromise
which resolves to a module with adefault
export containing a React component.
如果您将 SibaCard
组件的导出从命名导出更改为默认导出,它应该会按预期工作。
export default class SibaCard extends React.Component<ICardProps, ICardState> {
// ...
}
关于javascript - 收到解析为 : undefined. 的 promise promise 元素必须解析为类或函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53223140/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!