英文:
Type script: Type '(close: any) => Element' is not assignable to type 'ReactNode'
问题
I'm adding a popup in my TypeScript, and I just can't solve this issue:
Type '(close: any) => Element' is not assignable to type 'ReactNode'.
I've tried making it (close: () => void)
, but it is still not working. I've tried different solutions I can find, but none of them are working (I mean the code is working right; it's just that the error still pops up), so I can't run it on Vercel.
英文:
I'm adding a popup in my type script and i just can't solve this issue
Type '(close: any) => Element' is not assignable to type 'ReactNode'.
<Popup
trigger={
<button
className="fixed bottom-10 right-10 h-20 w-20 justify-center flex items-center bg-blue-200 rounded-lg hover:bg-blue-500"
onClick={() => handleResult()}
>
<Submit />
</button>
}
closeOnDocumentClick={false}
modal
>
{(close) => (
<div className="fixed right-1/2 top-1/2 h-32 border-2 w-64 bg-slate-300 border-slate-400 flex items-center justify-center rounded-xl">
<button
className="absolute right-1 top-1 rounded-xl border-2 h-7 w-10 bg-red-500 "
onClick={() => close()}
>
<p> x</p>
</button>
<Link
to="/result"
state={{ diagnosisResult: result, remark: remark }}
className={textStyle}
>
View Result Here!!!
</Link>
</div>
)}
</Popup>
i've tried making it (close : ()=>void)
but it is still not working, all tried different solution i can find but all are not working(i mean the code is working right its just that error still pop up) so i can't run it on vercel
答案1
得分: 0
在<Popup>标签内部,你只是声明了一个箭头函数((close : any) => Element),而没有调用它。我将你的函数用括号括起来并调用了它:
((param : any) => {doThing()})() // <- 在结尾加上 () 来调用你的函数
你编辑后的代码:
<Popup
trigger={
<button
className="fixed bottom-10 right-10 h-20 w-20 justify-center flex items-center bg-blue-200 rounded-lg hover:bg-blue-500"
onClick={() => handleResult()}
>
<Submit />
</button>
}
closeOnDocumentClick={false}
modal
>
{((close) => (
<div className="fixed right-1/2 top-1/2 h-32 border-2 w-64 bg-slate-300 border-slate-400 flex items-center justify-center rounded-xl">
{//...}
</div>
))()}
</Popup>
英文:
Inside <Popup>, You are just delcaring you arrow function ((close : any) => Element ) withtout calling it. I just wrap your function with parentheses and call you function:
((param : any) => {doThing()})() // <- () at this end to call your function
Your edited code
<Popup
trigger={
<button
className="fixed bottom-10 right-10 h-20 w-20 justify-center flex items-center bg-blue-200 rounded-lg hover:bg-blue-500"
onClick={() => handleResult()}
>
<Submit />
</button>
}
closeOnDocumentClick={false}
modal
>
{((close) => (
<div className="fixed right-1/2 top-1/2 h-32 border-2 w-64 bg-slate-300 border-slate-400 flex items-center justify-center rounded-xl">
{//...}
</div>
))()}
</Popup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论