类型脚本: 类型 ‘(close: any) => Element’ 无法分配给类型 ‘ReactNode’

huangapple go评论146阅读模式
英文:

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) =&gt; {doThing()})() // &lt;- 在结尾加上 () 来调用你的函数

你编辑后的代码:

&lt;Popup
    trigger={
        &lt;button
            className=&quot;fixed bottom-10 right-10 h-20 w-20 justify-center flex items-center bg-blue-200 rounded-lg hover:bg-blue-500&quot;
            onClick={() =&gt; handleResult()}
        &gt;
            &lt;Submit /&gt;
        &lt;/button&gt;
    }
    closeOnDocumentClick={false}
    modal
&gt;
    {((close) =&gt; (
        &lt;div className=&quot;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&quot;&gt;
            {//...}
        &lt;/div&gt;
    ))()}
&lt;/Popup&gt;
英文:

Inside &lt;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) =&gt; {doThing()})() // &lt;- () at this end to call your function

Your edited code

     &lt;Popup
        trigger={
          &lt;button
            className=&quot;fixed bottom-10 right-10 h-20 w-20 justify-center flex items-center bg-blue-200 rounded-lg hover:bg-blue-500&quot;
            onClick={() =&gt; handleResult()}
          &gt;
            &lt;Submit /&gt;
          &lt;/button&gt;
        }
        closeOnDocumentClick={false}
        modal
      &gt;
        {((close) =&gt; (
          &lt;div className=&quot;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&quot;&gt;
           {//...}
          &lt;/div&gt;
        ))()}
      &lt;/Popup&gt;

huangapple
  • 本文由 发表于 2023年5月6日 19:39:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定