Open tangway opened 5 months ago
make this component modular so that it can be reusable for hints and bonus qns and also if it doesnt work out for the flow of the game it can be removed with more ease
looking at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog#examples to see how i can use the <dialog>
tag. decided to use it as:
.showModal()
methodthe only downside to using it is older browsers do not support it, for eg. IE and older versions of FF and Safari
to use the .showModal()
and .close()
methods from the HTMLDialogElement interface you have to manipulate the DOM but this does not fit the React paradigm as you risk introducing inconsistencies between the virtual DOM (the representation of the page stored in memory managed by React) and the real DOM (what's actually displayed in the browser window). These inconsistencies can cause unexpected behaviors, bugs, and poor performance.
a suggested workaround is to use useRef
to manipulate the DOM as shown here: https://medium.com/@bomber.marek/how-to-use-dialog-in-react-easy-modals-tooltips-81e44d570c8a
in the article linked above it also describes how using React.createPortal
is more cumbersome than using the dialog
element:
ReactDOM.createPortal vs dialog
Before the
This API allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component.
In the context of modals, ReactDOM.createPortal is used to append the modal component directly to the body element or another container outside the main React application. Doing this avoids CSS stacking context issues and makes the modal appear on top of other elements.
However, using ReactDOM.createPortal requires you to manage the state of the modal (whether it's open or closed) and handle the appending and removing of the modal component from the DOM. This adds unnecessary complexity and might cause additional re-renders.
On the other hand, the
correct
state