) => void) | undefined'.",reactjs"/>

首页 > 解决方案 > onClick "Type 'void' is not assignable to type '((event: MouseEvent) => void) | undefined'."

问题描述

const thing = () => {

let selectedPage = "hello"

const addCduPageButton = () => {
 return (
     <div>
      <button onClick={addCduPage(selectedPage)}>Add Page</button>
     </div>
    )
  }

const addCduPage = (value: string) => {
      console.log(value)
}

return(
    <div>
      {addCduPageButton}
    </div>
  )
}

export default thing;

https://i.stack.imgur.com/NJN1U.png

Type 'void' is not assignable to type '((event: MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined'.

I am not understanding the issue with the onClick property of the button.

标签: reactjs

解决方案


推荐阅读