admin管理员组文章数量:1287646
import { createContext, ReactNode } from "react"
interface CascaderProps<T> {
getLabel: (item: T) => string
}
export const createCascaderContext = <T,>(
defaultValue: CascaderProps<T> | null
) => {
return createContext(defaultValue)
}
const CascaderContext = createCascaderContext(null)
export const CascaderProvider = <T,>(
context: CascaderProps<T>,
children?: ReactNode
) => {
return (
<CascaderContext.Provider value={context}>
{children}
</CascaderContext.Provider>
)
}
export default CascaderContext
I can't use generic T, ts infers T as unknown, what is the correct way to do it?
2025-2-24 update
Maybe I misunderstood, I think this is caused by the lack of support for Typescript in the React library. If you think this question is the same as the previous one I asked, please explain it in detail.
2025-2-24 update
I checked this answer but it uses any
and it doesn't make sense to solve the problem like that.
本文标签: reactjsReact ContextProvider Generics T are not acceptedStack Overflow
版权声明:本文标题:reactjs - React Context.Provider Generics T are not accepted - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741315789a2371906.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论