![](/img/trans.png)
[英]How to transform a React Class Component with generic props to Function Component in Typescript?
[英]Use typescript generic to connect props to state in React class component
我有没有办法让 state 类型取决于传入的道具类型?
type FooProps = {
allItems: any[]
}
type FooState = {
items: any[]
}
export default class Foo extends React.Component<FooProps, FooState> {
你试过了吗?
interface FooProps<T> {
allItems: T[]
}
interface FooState<T> {
items: T[]
}
export default class Foo<T> extends React.Component<FooProps<T>, FooState<T>> {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.