Skip to content
Advertisement

Copy/Paste of Reactjs-Popup Example from the site does not work with useState

I’m trying out example code provided by Reactjs-Popup at https://react-popup.elazizi.com/controlled-popup/, but it doesn’t seem to work. I pretty much copy/pasted the code. What am I missing? I can make the popup to work if I remove all references to “useState”.

index.js

JavaScript

ControlledPopup.jsx

JavaScript

Advertisement

Answer

I think your problem comes from the way you’re trying to render your component in index.js.
Since if I try to render it the way I’m used to, the code you’ve provided worked.

I implemented it like this:

index.js

JavaScript

App.js (here I use your provided component)

JavaScript

Check out this playground for the whole implementation.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement