首页 > 解决方案 > 为什么显示红色偶数代码是正确的?

问题描述

我正在开发一个反应原生应用程序。我正在为我的工作使用 Visual Studio Code。为什么我的代码中出现红色警报。

当我将鼠标悬停在它上面时,我得到

"[ts] Property 'loading' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'.
any"

我认为我的代码没有任何问题,但它仍然显示为红色。谁能告诉我这是什么问题。

红色

标签: react-nativevisual-studio-codereact-redux

解决方案


您必须在道具中声明您的加载。这是一个小例子:

type BooksTableProps = {
readonly data: Array<data>;
readonly pagination: Pagination;
readonly loading: boolean;
readonly error: string;  // or whatever

actions here      
}

在您的渲染方法中使用加载:

render() {
  const {
    loading,
    pagination,
    data,                
  } = this.props;

  return (
    <div>           
      <Table          
        columns={this.columns}
        dataSource={data}          
        loading={loading}
        pagination={pagination}
        onChange={this.handleTableChange}
      />
    </div>                
  )
}

推荐阅读