admin管理员组

文章数量:1394099

I have a problem where I always get my function changePage undefined or not a function error on the chilled component!

parent

export default function App() {

  const [page, setPage] = React.useState("Dashboard");

  const changePage = (page) => {
    setPage(page);
  }

    return (
      <>
        <MainPage setPageHook={changePage}/>
      </>
    )

}

child

export default function App( {props}) {

return (
  <p onClick={() => props.changePage("Dashboard") </p>
)
}

why I'm getting this error ?

I'm expecting to use the function on the child component but it's not passing!

本文标签: reactjsPassing a function as props from parent to child component using vite react jsStack Overflow