【问题标题】:Typescript interface for custom map自定义地图的打字稿界面
【发布时间】:2019-12-02 09:31:22
【问题描述】:

我有一个这样的界面:

export interface IMyMap {
  [index: string]: RefObject<HTMLElement>;
}

根据文档创建:Indexable Types

我想在 React useState 钩子中使用它,但我似乎无法让它工作。 我将如何实际使用这个界面?

【问题讨论】:

  • 你能分享你的useState代码吗?

标签: reactjs typescript react-hooks


【解决方案1】:

你可以像 useState 这样使用它

const [state, setState] = React.useState<IMyMap>({/* Your initial value here */});

【讨论】:

  • 我试过了,它接受了,但是当我尝试使用它时,状态并没有变成地图。
  • 那么您需要在问题中提供更多详细信息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-16
  • 2016-09-22
  • 2016-06-21
  • 2022-06-23
  • 2021-12-24
  • 2018-02-04
  • 2021-12-04
相关资源
最近更新 更多