【问题标题】:How to add custom attribute in React typescript如何在 React 打字稿中添加自定义属性
【发布时间】:2019-08-22 12:09:53
【问题描述】:

这对我不起作用: Property does not exist on type 'DetailedHTMLProps, HTMLDivElement>' with React 16

默认情况下我没有 index.d.ts,我创建了一个,但没有帮助,所以我把它放在一个组件文件夹中,然后 ts 开始抱怨“useState 不从 React 导出”。

我是打字稿的新手。 我需要这样的东西:

<div customAtribute="foo"/>bar</div>

【问题讨论】:

  • 你需要按顺序学习 JavaScript、TypeScript 和 React 的基础知识。

标签: reactjs typescript


【解决方案1】:

它以某种方式工作......感谢大家:)

declare namespace React {
    interface HTMLAttributes<T> extends DOMAttributes<T> {
        customAttribute?: string;
    }
}

【讨论】:

    猜你喜欢
    • 2023-01-16
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 2020-03-18
    • 2019-04-15
    • 1970-01-01
    相关资源
    最近更新 更多