使用React-Redux用途和打字稿



试图使用新的用途钩(请参见下文示例(React-Redux typeScript的错误,错误地说该函数不存在:

Module '"../../../node_modules/@types/react-redux"' has no exported member 'useSelector'.  TS2305

示例

import * as React from "react"
import { useSelector } from "react-redux"
import { Message } from "./Message"
export const MessageContainer = () => {
  const searchValue = useSelector((state) => state.search)
  return (
    <Message searchValue={searchValue} />
  )
}

使用的版本:" React-Redux":"^7.1.0-Alpha.5"@type/react-redux":"^7.0.9"

下面的代码从redux doc本身就打字稿
打字稿redux jatical

interface RootState {
      isOn: boolean
    }
// TS infers type: (state: RootState) => boolean
const selectIsOn = (state: RootState) => state.isOn
// TS infers `isOn` is boolean
const isOn = useSelector(selectIsOn)

正如稍后添加之前所说的那样,但是如果您使用钩子

,最好像这样编写选择器

相关内容

  • 没有找到相关文章

最新更新