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

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

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744678654a4587481.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信