[英]Why does it complain about type {intrinsicattributes && true} or type {intrinsicattributes && false} are not assignable using react and typescript?
i have code like below,我有如下代码,
function Parent() {
const count1 = 2;
const count2 = 4;
const isCount = count1 < 0 || count2 < 0; //setting isCount here
return show ? (
<Dialog>
<Body>soemthing</Body>
<Actions
isAdminAndisCount={isAdminAndisCount}
>
{((isAdmin && !isCount) || !isAdmin) && (
<Text onClick={onHide}>Close</Text>
)}
{isAdmin ? ( //to refactor this
isCount ? (
<a href="eee">email us</a>
) : (
<a href="mmm">add</a>
)
) : null}
</Actions>
</Dialog>
) : null;
}
this works fine but refactored this code这工作正常,但重构了这段代码
{isAdmin ? ( //to refactor this
isCount ? (
<a href="eee">email us</a>
) : (
<a href="mmm">add</a>
)
) : null}
**TO**
const RenderLink = ( isCount: boolean ) =>
isCount ? <a href="eee">email us</a> : <a href="mmm">add</a>;
{isAdmin && <RenderLink isCount={isCount} />} //here is the error
But this displays link for email us even though !isCount and i see error但这会显示 email 我们的链接,即使 !isCount 并且我看到错误
error "type {isCount: boolean is not assignable to type {intrinisicAttributes && false} or type {intrinsicAttributes && true}错误“类型 {isCount: boolean 不可分配给类型 {intrinisicAttributes && false} 或类型 {intrinsicAttributes && true}
Could someone help me fix this.有人可以帮我解决这个问题。 thanks.
谢谢。
The first arg in React functional components is their props which is an object of received props. React 功能组件中的第一个 arg 是它们的 props,它是接收到的 props 的 object。 So change this line:
所以改变这一行:
const RenderLink = ( isCount: boolean ) =>
To:至:
interface Props {
isCount: boolean
}
const RenderLink: React.FC<Props> = ({isCount}) =>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.