0

I'm trying to call a Modal I made in another class. I simply want to pass a boolean parameter to open or close it.

Calling the modal:

<CourseModal show={true} /> 

Modal function:

export default function CourseModal(show) {
  return (
    <Modal open={show}>
        <ModalContent />
    </Modal>
  );
}

However when I do this, I get the following error:

enter image description here

Why does this happen? It says it expects a boolean, but it clearly is? Thanks in advance!

SJ19
  • 1,933
  • 6
  • 35
  • 68

1 Answers1

2

Currently, you pass the props object itself, you just named it show.

export default function CourseModal({ show }) {
  return (
    <Modal open={show}>
      ...
    </Modal>
  );
}

// You called it show instead of props
export default function CourseModal(props) {
  return (
    <Modal open={props.show}>
      ...
    </Modal>
  );
}

import PropTypes from 'prop-types';
const CourseModal = ({ show }) => {
  return (
    <Modal open={show}>
      ...
    </Modal>
  );
};

CourseModal.propTypes = {
  show: PropTypes.bool;
}

export default CourseModal;

Also, in JSX you don't have to pass true boolean, you can write:

// Same as show={true}
<CourseModal show /> 
Dennis Vash
  • 50,196
  • 9
  • 100
  • 118