0
이미 ComponentType으로 입력 된 구성 요소에 다른 구성 요소를 부착 할 수 있습니까?ComponentType에 다른 구성 요소를 연결하는 방법은 무엇입니까?
예컨대 :
type Props = {
name: string,
}
const Header: ComponentType<Props> = ({ props }) => (<h1>{name}</h1>)
const SubHeader: ComponentType<Props> = ({ props }) => (<h2>{name}</h2>)
Header.SubHeader = SubHeader // this is causes a flow error due to ComponentType
예는 조금 인위적인이지만, HOCs 또는 styled-components
를 사용하는 경우 ComponentType
에 강제 수동 때때로 필요하다.
교차로 유형을 사용하여 '헤더 유형'을 확장 할 수 있습니까 (https://stackoverflow.com/questions/42582880/flow-create-a-flow-type-by-extending-another-type)? –
그래, 교차로 작업을 할 것입니다 :'const Header : ComponentType & {SubHeader ?: ComponentType }' –
흠, 보통이 방법이 효과가 있다고 생각하지만'styled-components'를 사용하면'styled() '모든 교차 유형을 거부합니다. 나는 이것에 관해 무엇을해야하는지 그들에게 물을 것이다. 그러나 이것은 대답한다 :). 어느 쪽이든 대답하고 싶습니까? –