【发布时间】:2022-03-31 02:31:50
【问题描述】:
我是 React 的新手,很难理解我收到的错误。我设法修复了这种类型的其他一些错误,但是这个特定的错误让我迷失了。在打字稿文件中,我有:
export interface FarmsProps {
tokenMode?: boolean
}
然后再往下
const Farms: React.FC<FarmsProps> = (farmsProps) => {
const { path } = useRouteMatch()
const TranslateString = useI18n()
const farms = useFarms();
const prices = usePrices()
const farmsLP = useFarms()
const cakePrice = usePriceCakeBusd()
const bnbPrice = usePriceBnbBusd()
const { account, ethereum }: { account: string; ethereum: provider } = useWallet()
const { tokenMode } = farmsProps;
const [modalOpen, setModalOpen] = useState(true)
const handleModal = async () => {
setModalOpen(!modalOpen)
}
编译时出现如下错误:
Failed to compile.
src/views/LiqPools/Farms.tsx
Line 26:6: 'tokenMode' PropType is defined but prop is never used react/no-unused-prop-types
Search for the keywords to learn more about each error.
非常感谢任何指导。
【问题讨论】:
-
看起来像是来自 linter 的警告?您正在创建
tokenMode变量,但看起来您实际上并没有在任何地方使用它。只需删除const { tokenMode } = farmsProps;或在某处使用它。 -
@sallf 我尝试删除该行,但它不能解决问题。这是一个 linter 错误,我设法通过删除行来修复以前的一些错误,但不是这一行。这个 React 应用程序是分叉的,这就是为什么我很难理解发生了什么
-
它实际上不应该破坏你的代码。也许试试disable the rule?
-
@sallf 我也厌倦了;他们在 linter 文件中将 react/prop-types 设置为“关闭”,并附注说他们不使用 prop-types。我将其设置为 0 但没有运气。我还在文件顶部添加了 /* eslint-disable react/prop-types */,仍然没有区别
-
要禁用的是
react/no-unused-prop-types而不是react/prop-types。您还应该能够turn linter errors into warnings,这样他们就不会破坏您的构建。