具有TypeScript和反应的HOC上下文

问题描述 投票:0回答:1

我的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)

[当我从父级调用此子级组件时:enter image description here

道具titleLabel不会通过打字稿传递给子组件<DateComponentCustom />

没有打字稿就可以正常工作>>

我有一个非常简单的带有上下文的子组件:import * as React from'react'import {withContext} from'../withContext'import {Context} from'../Context.type'type State = {} type道具= ...

reactjs typescript
1个回答
0
投票

应该使用TypeScript interfaces,而不是使用类型别名。另外,您可能想用更具体的名称定义props接口。

© www.soinside.com 2019 - 2024. All rights reserved.