当我尝试将钩子传递给功能组件时,出现此错误:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(requestCode == 123 && resultCode == Activity.RESULT_OK){
tvCode.setText(data.getExtras().getString("inputText",""));
} else {
super.onActivityResult(requestCode, resultCode, data)
}
}
Type '() => void' is not assignable to type 'FunctionComponent<InputProps>'.
Type 'void' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | null'.
答案 0 :(得分:1)
您的功能组件签名(React.FunctionComponent)与您的功能componenet实现(()=> {})不匹配
{{1}}
如果查看FunctionComponent接口,您会注意到它必须实现 像(props:P&{children ?: ReactNode},context ?: any)这样的函数:ReactElement | null;
{{1}}