最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Passing a function as props from parent to child component using vite react js - Stack Overflow

programmeradmin1浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论