我的context有一个非常简单的子组件:
import * as React from 'react'
import { withContext } from '../withContext'
import { Context } from '../Context.type'
type State = {}
type Props = {
titleLabel: string
context: Context
}
class DateComponentCustom extends React.Component<Props, State> {
render() {
return <>{this.props.context.me && <div>{this.props.titleLabel}</div>}</>
}
}
export default withContext(DateComponentCustom)
道具titleLabel
不会通过打字稿传递给子组件<DateComponentCustom />
。
没有打字稿就可以正常工作>>
我有一个非常简单的带有上下文的子组件:import * as React from'react'import {withContext} from'../withContext'import {Context} from'../Context.type'type State = {} type道具= ...
应该使用TypeScript interfaces,而不是使用类型别名。另外,您可能想用更具体的名称定义props接口。