skip to Main Content

I am trying to call **toggleSideBar **received in **SideBar **component as a prop. But it is giving an error that **toggleSideBar **is not a function. Actually I am trying to call toggleSideBar in another callback function

Here is the code

const Sidebar = (props) => {
  const { isOpenSidebar, **toggleSideBar **} = props;
  console.log(isOpenSidebar);
  const closeSideBar = () => {
**toggleSideBar();**
 };

2

Answers


  1. looks like you are not passing the function correctly in the component, make sure it should be like this

    <Sidebar toggleSideBar={yourActualFunction} />
    Login or Signup to reply.
  2. Seems like you are passing function like this

    <YourSidebar toggleSideBar={yourActualFunction()} />
    

    Don’t call the function while passing. Make it like this

    <YourSidebar toggleSideBar={yourActualFunction} />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search