有没有办法将类型作为参数或其他东西传递给另一个组件?像这样的东西,传递一个动态类型,这样我就可以在我的自定义钩子之外自动输入第三方钩子
const hook = useCustomHook<DynamicType>()
并在自定义钩子中做类似的事情
export const useCustomHook = () => {
return useAnotherLibraryHook<DynamicType>()
}
这些称为泛型类型参数。简单的说:
export const useCustomHook = <T extends any>() => {
return useAnotherLibraryHook<T>()
}
但是,您将希望与any
与库相关的更窄的东西(可能是其内部类型之一)进行交换。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句