TypeScript에서 컴파일 할 React.createElement를 가져올 수 없습니다.TypeScript/JSX의 React.createElement에 대한 올바른 구문
interface IColorPickerProps {
}
interface IColorPickerState {
}
class ColorPicker extends React.Component<IColorPickerProps, IColorPickerState> {
constructor(props: IColorPickerProps) {
super(props);
}
}
구성 요소 만들기 : 내가 생성자를 제거하면
Argument of type 'typeof ColorPicker' is not assignable to parameter of type 'string | ComponentClass<IColorPickerProps> | StatelessComponent<IColorPickerProps>'.
Type 'typeof ColorPicker' is not assignable to type 'StatelessComponent<IColorPickerProps>'.
Type 'typeof ColorPicker' provides no match for the signature '(props: IColorPickerProps & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
이 오류가 사라집니다 :
let props: any = {}
React.createElement(ColorPicker, props)
나는이 컴파일 오류가 발생합니다. 소품을 동적으로 전달해야하므로 구문을 사용할 수 없습니다. 어떤 아이디어?
'React.createElement (ColorPicker, props)'는 왜' '일까요? –
Props는 ColorPicker를 만드는 클래스에 매개 변수로 동적으로 전달되기 때문에. ' ''React.createElement (ColorPicker, props)'는 컴파일 타임 검사를하지 못합니다. –
sixtstorm1