feat(react): add setupIonicReact function (#24254)

resolves #24139
This commit is contained in:
Liam DeBeasi
2021-11-22 15:29:47 -05:00
committed by GitHub
parent 3c4f9fd2d5
commit 55db38ddc5
6 changed files with 59 additions and 17 deletions

View File

@ -29,12 +29,15 @@ This is a comprehensive list of the breaking changes introduced in the major ver
- [Config](#config) - [Config](#config)
* [Transition Shadow](#transition-shadow) * [Transition Shadow](#transition-shadow)
- [Angular](#angular) - [Angular](#angular)
* [Config Provider](#config-provider) * [Config](#config-1)
- [Vue](#vue) - [Vue](#vue)
* [Config](#config-2)
* [Tabs Config](#tabs-config) * [Tabs Config](#tabs-config)
* [Tabs Router Outlet](#tabs-router-outlet) * [Tabs Router Outlet](#tabs-router-outlet)
* [Overlay Events](#overlay-events) * [Overlay Events](#overlay-events)
* [Utility Function Types](#utility-function-types) * [Utility Function Types](#utility-function-types)
- [React](#react)
* [Config](#config-3)
- [Browser and Platform Support](#browser-and-platform-support) - [Browser and Platform Support](#browser-and-platform-support)
@ -164,13 +167,46 @@ The `experimentalTransitionShadow` config option has been removed. The transitio
### Angular ### Angular
#### Config Provider #### Config
The `Config.set()` method has been removed. See https://ionicframework.com/docs/angular/config for examples on how to set config globally, per-component, and per-platform. The `Config.set()` method has been removed. See https://ionicframework.com/docs/angular/config for examples on how to set config globally, per-component, and per-platform.
Additionally, the `setupConfig` function is no longer exported from `@ionic/angular`. Developers should use `IonicModule.forRoot` to set the config instead. See https://ionicframework.com/docs/angular/config for more information.
### React
#### Config
All Ionic React applications must now import `setupIonicReact` from `@ionic/react` and call it. If you are setting a custom config with `setupConfig`, pass your config directly to `setupIonicReact` instead:
**Old**
```javascript
import { setupConfig } from '@ionic/react';
setupConfig({
mode: 'md'
})
```
**New**
```javascript
import { setupIonicReact } from '@ionic/react';
setupIonicReact({
mode: 'md'
})
```
Note that all Ionic React applications must call `setupIonicReact` even if they are not setting custom configuration.
Additionally, the `setupConfig` function is no longer exported from `@ionic/react`.
### Vue ### Vue
#### Config
The `setupConfig` function is no longer exported from `@ionic/vue`. Developers should pass their config into the `IonicVue` plugin. See https://ionicframework.com/docs/vue/config for more information.
#### Tabs Config #### Tabs Config
Support for child routes nested inside of tabs has been removed to better conform to Vue Router's best practices. Additional routes should be written as sibling routes with the parent tab as the path prefix: Support for child routes nested inside of tabs has been removed to better conform to Vue Router's best practices. Additional routes should be written as sibling routes with the parent tab as the path prefix:

View File

@ -50,7 +50,6 @@ export {
createGesture, createGesture,
iosTransitionAnimation, iosTransitionAnimation,
mdTransitionAnimation, mdTransitionAnimation,
setupConfig,
IonicSwiper, IonicSwiper,
IonicSlides, IonicSlides,
getPlatforms, getPlatforms,

View File

@ -1,4 +1,4 @@
import { IonApp } from '@ionic/react'; import { IonApp, setupIonicReact } from '@ionic/react';
import React from 'react'; import React from 'react';
import { Route } from 'react-router-dom'; import { Route } from 'react-router-dom';
@ -36,6 +36,9 @@ import Refs from './pages/refs/Refs';
import DynamicIonpageClassnames from './pages/dynamic-ionpage-classnames/DynamicIonpageClassnames'; import DynamicIonpageClassnames from './pages/dynamic-ionpage-classnames/DynamicIonpageClassnames';
import Tabs from './pages/tabs/Tabs'; import Tabs from './pages/tabs/Tabs';
import TabsSecondary from './pages/tabs/TabsSecondary'; import TabsSecondary from './pages/tabs/TabsSecondary';
setupIonicReact();
const App: React.FC = () => { const App: React.FC = () => {
return ( return (
<IonApp> <IonApp>

View File

@ -1,4 +1,4 @@
import { initialize } from '@ionic/core/components'; import { IonicConfig, initialize } from '@ionic/core/components';
import { addIcons } from 'ionicons'; import { addIcons } from 'ionicons';
import { import {
arrowBackSharp, arrowBackSharp,
@ -23,7 +23,6 @@ export {
createGesture, createGesture,
iosTransitionAnimation, iosTransitionAnimation,
mdTransitionAnimation, mdTransitionAnimation,
setupConfig,
IonicSwiper, IonicSwiper,
IonicSlides, IonicSlides,
getTimeGivenProgression, getTimeGivenProgression,
@ -190,13 +189,17 @@ addIcons({
'search-sharp': searchSharp, 'search-sharp': searchSharp,
}); });
/** export const setupIonicReact = (config: IonicConfig = {}) => {
* By default Ionic Framework hides elements that /**
* are not hydrated, but in the CE build there is no * By default Ionic Framework hides elements that
* hydration. * are not hydrated, but in the CE build there is no
* TODO: Remove when all integrations have been * hydration.
* migrated to CE build. * TODO: Remove when all integrations have been
*/ * migrated to CE build.
document.documentElement.classList.add('ion-ce'); */
document.documentElement.classList.add('ion-ce');
initialize(); initialize({
...config
});
}

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { Route } from 'react-router-dom'; import { Route } from 'react-router-dom';
import { IonApp } from '@ionic/react'; import { IonApp, setupIonicReact } from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router'; import { IonReactRouter } from '@ionic/react-router';
/* Core CSS required for Ionic components to work properly */ /* Core CSS required for Ionic components to work properly */
@ -25,6 +25,8 @@ import Main from './pages/Main';
import OverlayHooks from './pages/overlay-hooks/OverlayHooks'; import OverlayHooks from './pages/overlay-hooks/OverlayHooks';
import OverlayComponents from './pages/overlay-components/OverlayComponents'; import OverlayComponents from './pages/overlay-components/OverlayComponents';
setupIonicReact();
const App: React.FC = () => ( const App: React.FC = () => (
<IonApp> <IonApp>
<IonReactRouter> <IonReactRouter>

View File

@ -40,7 +40,6 @@ export {
createGesture, createGesture,
iosTransitionAnimation, iosTransitionAnimation,
mdTransitionAnimation, mdTransitionAnimation,
setupConfig,
IonicSwiper, IonicSwiper,
IonicSlides, IonicSlides,
getPlatforms, getPlatforms,