reactjs - 接口道具声明
问题描述
我是 Typescript 的新手,我被一些界面道具困住了。有一个错误说“属性'服务'不存在类型'IntrinsicAttributes & AkkordionProps [] ”,我不明白,因为我在我的接口声明中看到了服务,所以我现在迷失了。
这是调用 BusinessPage 组件的主要组件:
<BusinessPage services={services} />
这是 BusinessPage.tsx 组件:
export interface AkkordionListProps {
services: {
name: string
services: {
name: string
content: string
link: string
}[]
}
}
export interface AkkordionProps {
services: AkkordionListProps[]
}
export const BusinessPage = (services: AkkordionProps[]): JSX.Element => {}
谢谢 :)
解决方案
BUsinessPage
是反应组件。React 总是期望一个对象作为 prop 而不是数组:
import React from 'react'
export interface AkkordionListProps {
services: {
name: string
services: {
name: string
content: string
link: string
}[]
}
}
export interface AkkordionProps {
services: AkkordionListProps[]
}
export const BusinessPage = (props: AkkordionProps): JSX.Element => {
return <div></div>
}
推荐阅读
- conv-neural-network - colab 模块“tensorflow”没有属性“占位符”
- javascript - Glidejs 带有 iframe 内容
- reactjs - 如何从 API 调用中提取数据
- php - 在 PHP Interpreters、PhpStorm 2020.3、Laravel 8 中未检测到 PHP
- python - 在继承单元格样式的同时插入多行
- spring-boot - Spring Boot JMS 客户端
- r - 是否有用于过滤大于 0 和用于自然对数计算的 rgee 函数(R Studio Google Earth Engine)?
- node.js - WebRTC调用在挂断期间抛出错误
- c++ - C++,在 for 循环中使用 getline 和 cin.ignore() 的问题。Getline 在 for 循环中被第二次迭代跳过
- javascript - ReactJS :: 如何在页面更改时仅显示相关菜单项并隐藏其他菜单项