簡體   English   中英

JS React /已聲明但從未使用過

[英]JS React /Declared but never used

我開始學習 JS 並且在我的功能中遇到了一些問題。 此功能的目標 - 顯示 1 列表格和 1 列復選框(每一行都應該是復選框)。

我的代碼:

import React from 'react';
import { Table, Spin } from 'antd';
import PropTypes from 'prop-types';
import { useFetch } from 'innroad.common.ui';
import * as apiService from 'services/ApiService';

const AccountType = (onSelectingItems) => {
  const [data, isLoading] = useFetch(apiService.getAccountType);

  return (
    <Spin spinning={isLoading}>
      <Table
        key="id"
        bordered="true"
        rowKey="id"
        dataSource={data}
        rowSelection={{ onChange: onSelectingItems }}
        pagination={false}
      >
        <Table.Column title="Account Type" dataIndex="accountType" />
      </Table>
    </Spin>
  );
};

AccountType.propTypes = {
  onSelectingItems: PropTypes.func,
};

AccountType.defaultProps = {
  onSelectingItems: () => { },
};

export default AccountType;

在這一行我得到錯誤( “'onSelectingItems' PropType 已定義,但從未使用過道具” )。 但是我在我的代碼中使用了這一行,我應該使用它。 我的錯誤是什么?

onSelectingItems: PropTypes.func,

您需要從道具中解構onSelectingItems

嘗試在此處更改您的代碼:

const AccountType = ({ onSelectingItems }) => {
  //code
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM