【问题标题】:JS React /Declared but never usedJS React /Declared 但从未使用过
【发布时间】:2020-10-07 07:47:09
【问题描述】:

我开始学习 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 已定义,但从未使用过 prop”)。但是我在我的代码中使用了这一行,我应该使用它。我的错误是什么?

onSelectingItems: PropTypes.func,

【问题讨论】:

  • 你是如何在父元素的 JSX 中使用 &lt;AccountType /&gt; 的?此外,功能组件接收props 参数,您已经对其进行了解构:const AccountType = ({ onSelectingItems }) =&gt; {

标签: javascript reactjs


【解决方案1】:

你需要从道具中解构onSelectingItems

尝试在此处更改您的代码:

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

【讨论】:

    猜你喜欢
    • 2020-06-06
    • 2021-03-20
    • 2021-05-02
    • 2020-09-01
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 2022-06-20
    相关资源
    最近更新 更多