如何调用react中功能组件中作为prop接收的函数?

问题描述 投票:0回答:1

我正在尝试调用 **toggleSideBar ** 在 **SideBar ** 组件中作为道具接收。但它给出了一个错误:**toggleSideBar **不是一个函数。实际上我正在尝试在另一个回调函数中调用toggleSideBar

这是代码

const Sidebar = (props) => {
  const { isOpenSidebar, **toggleSideBar **} = props;
  console.log(isOpenSidebar);
  const closeSideBar = () => {
**toggleSideBar();**
 };
reactjs react-props react-functional-component
1个回答
0
投票

看起来您没有在组件中正确传递函数,请确保它应该是这样的

<Sidebar toggleSideBar={yourActualFunction} />

© www.soinside.com 2019 - 2024. All rights reserved.