DEV Community

Discussion on: How to create an efficient Modal component in React using Hooks and Portals

Collapse
 
luishvdiaz profile image
Luis Humberto Vazquez Diaz

I see, the component with id modal ... I use typescript, it keeps giving the same error message :(

Thread Thread
 
tripol profile image
Ekanem

1) You can place the document.getElementById ('root') in a variable and add a null check. For example:

const portalDiv = document.getElementById('root')!

2) Pass the portalDiv as the second parameter AFTER the </> closing fragment