I have a modal that takes in an useState argument that is used to show or close the modal based on a button click. (close button is in the modal and show button is in a separate functional component).
When I try to use useState in jest I get the following error:
Invalid hook call. Hooks can only be called inside of the body of a function component
This is how my modal is defined:
export default function PDFViewer({modalVisible, setModalVisible, file, filename}: {modalVisible:boolean, setModalVisible:Dispatch<SetStateAction<boolean>>, file:string, filename?:string }): JSX.Element { ... Modal code ...}
Instead of using use state I am passing in a void function right now but that isn't very useful.
jest render:
const { getByText} = render(<AuthProvider><PDFViewer modalVisible={false} setModalVisible={function (value: React.SetStateAction<boolean>): void { throw new Error("Function not implemented."); } } file={""} /></AuthProvider> );
What is the best way to actually pass in a useState to the modal?