如何通过一个线性梯度的孩子?



这是我的代码,基本上我正在学习React Native,并得到了一个错误,而试图通过LinearGradient内部的孩子。

import React, { ReactNode } from "react";
import { LinearGradient } from "expo-linear-gradient"
import { styles } from "./styles"
import { theme } from "../../global/styles/theme"
type Props = {
children: ReactNode
}
export function Background({ children }: Props) {
const {secondary80, secondary100} = theme.colors;
return (
<LinearGradient
style={styles.container}
colors={[secondary80, secondary100]}
>
{children}
</LinearGradient>
)
}

完整的错误是:

(parameter) children: React.ReactNode<br>
No overload matches this call.
Overload 1 of 2, '(props: LinearGradientProps | Readonly<LinearGradientProps>): LinearGradient', gave the following error.<br>
Type 'ReactNode' is not assignable to type '((boolean | ReactChild | ReactFragment | ReactPortal) & (boolean | ReactChild | ReactFragment | ReactPortal)) | null | undefined'.<br>
Type '{}' is not assignable to type '((boolean | ReactChild | ReactFragment | ReactPortal) & (boolean | ReactChild | ReactFragment | ReactPortal)) | null | undefined'.<br>
Overload 2 of 2, '(props: LinearGradientProps, context: any): LinearGradient', gave the following error.<br>
Type 'ReactNode' is not assignable to type '((boolean | ReactChild | ReactFragment | ReactPortal) & (boolean | ReactChild | ReactFragment | ReactPortal)) | null | undefined'.ts(2769)<br>
index.d.ts(2320, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<LinearGradient> & Readonly<LinearGradientProps> & Readonly<...>'<br>
index.d.ts(2320, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<LinearGradient> & Readonly<LinearGradientProps> & Readonly<...>'

对于LinearGradient的props

<LinearGradient
style={styles.container}
colors={[secondary80, secondary100]}
children={children}>
</LinearGradient>

为子组件

<LinearGradient
style={styles.container}
colors={[secondary80, secondary100]}>
<children />
</LinearGradient>

最新更新