1

My (simplified) React component looks like:

import React from 'react';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';

export default function MyList(setPanel) {

  const handleClick = () => {
    console.log(setPanel);
    setPanel('support');
  };

  return (
    <List>
      <ListItem button key="Support" onClick={handleClick}>
        <ListItemText primary="Support" />
      </ListItem>
    </List>
  );
}

and the console log is showing setPanel to be a function but then I'm getting a

TypeError: setPanel is not a function

when I click on the ListItem in the app. What am I missing here?

1 Answer 1

2

You didn't destructure the props:

export default function MyList({setPanel}) 

Since props is an object containing setPanel, you are getting setPanel isn't a function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.