【问题标题】:Hook that is initialized with an empty array?用空数组初始化的钩子?
【发布时间】:2020-11-26 07:11:14
【问题描述】:

假设我们要创建类型为string[] 的Hook,并且没有元素。我在做

const def: string[] = []
const [selected, setSelected] = useState(def);

哪个有效。但是,我想知道是否有一种方法可以仅在一行中实现这一点。

【问题讨论】:

    标签: reactjs typescript react-hooks


    【解决方案1】:
    const [selected, setSelected] = useState<string[]>([]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 2012-08-22
      相关资源
      最近更新 更多