question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: new useIonModal hook for Ionic React renders component outside tree

See original GitHub issue

Bug Report

Ionic version:

[ ] 4.x [x ] 5.x [ ] 6.x

Current behavior: Just in case this behavior is unintended, the new useIonModal hook renders the modal component passed to present() outside of the react tree as a sibling of the root node. Because of this, the component used has no access to any app-wide context that wraps the main “App” component that the calling component belongs to.

Expected behavior: Render the component for the modal inside the root react tree.

Steps to reproduce:

Follow the Ionic docs for rendering/presenting a React modal using useIonModal() hook.

Related code:

Here’s a screenshot where you see the component that the hook renders next to the component tree instead of inside it (either as a child or sibling of <App />) Screen Shot 2021-06-25 at 7 27 22 PM

Other information:

In case this is the intended behavior for the useIonModal hook - this may be an opportunity to mention in the docs when deciding whether to use the original <IonModal> wrapping component or the hook. Perhaps that the hook is meant for modals that don’t need access to app-wide data and for those and other complex use-cases continue to use the <IonModal> component. I would be happy to PR to the docs if needed! Thanks

Ionic info:

Ionic:

   Ionic CLI       : 5.4.16 (/Users/rene/.npm/_npx/23301/lib/node_modules/ionic)
   Ionic Framework : @ionic/react 5.6.10

Capacitor:

   Capacitor CLI   : 2.4.6
   @capacitor/core : 2.4.7

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v12.16.3 (/Users/rene/.nvm/versions/node/v12.16.3/bin/node)
   npm    : 6.14.4
   OS     : macOS Mojave

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
liamdebeasicommented, Nov 3, 2021

Thanks for the issue. The original issue here was resolved via https://github.com/ionic-team/ionic-framework/commit/f3e492c897c8cda2b98050156f130654f4d7014a. The Preact issue has been resolved via https://github.com/ionic-team/ionic-framework/pull/24132, and a fix will be available in an upcoming release of Ionic 6.

1reaction
piotr-czcommented, Nov 3, 2021

@liamdebeasi Thanks, https://github.com/ionic-team/ionic-framework/pull/24132 solved the issue in VSCode, however I’m unable to build. I’ll post details in referenced PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the New Overlay Hooks for Ionic React
In Ionic React 5.6, we packaged up a new set of hooks for controlling our overlay components that we think you might like....
Read more >
@ionic/core | Yarn - Package Manager
Ionic is an open source app development toolkit for building modern, fast, top-quality cross-platform native and Progressive Web Apps from a single codebase ......
Read more >
How to use the Ionic 6 Bottom Sheet Modal ... - YouTube
The release of v6 for Ionic Framework brought the addition of the Bottom Sheet or "Sheet Modal" component to our toolbox.
Read more >
In an Ionic React application, how can i change the value for ...
In an Ionic React functional component, i have tried to instantiate a modal for this purpose using the useIonModal hook with the canDismiss ......
Read more >
How To Build a Modal With Ionic and React
I'm having fun with Ionic React these days and am, therefore, ... the display state to false , is still rendered outside of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found