bug: @ionic/react: ion-slides: Layout breaks when adding slides dynamically
See original GitHub issueBug Report
Ionic version:
[cli] 5.2.2 [@ionic/react] 0.0.6
Current behavior:
When slides are being added dynamically, the layout of the slides component breaks and newly added slides sit outside of the swiper-wrapper. Issue persists even after calling component’s update()
method.
Expected behavior:
When adding additional slides, slides component should be updated to properly display those added slides.
Steps to reproduce:
-
Start a new React blank project:
ionic start slides blank --type=react
-
Use the following
Home.tsx
template:
import {IonContent, IonHeader, IonTitle, IonToolbar, IonSlides, IonSlide, IonButton} from '@ionic/react';
import React from 'react';
const slideOpts = {
initialSlide: 0,
speed: 400
};
class Home extends React.Component<any, any> {
private _slidesRef = React.createRef<any>();
constructor(props: any) {
super(props);
this.state = {
slides: [
'1 Slide',
'2 Slide',
]
};
}
onSlidesAdd() {
this.setState({
slides: [
'1 Slide',
'2 Slide',
'3 Slide',
'4 Slide',
'5 Slide'
]
}, async () => {
await this._slidesRef.current.update();
console.log('IonSlides updated, but issue persists');
});
}
render() {
const {slides} = this.state;
return (
<>
<IonHeader>
<IonToolbar>
<IonTitle>Ionic Blank</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonButton onClick={() => this.onSlidesAdd()}>
Add slides
</IonButton>
<IonSlides ref={this._slidesRef} pager={true} options={slideOpts}>
{slides.map((slide: any) => (
<IonSlide key={parseInt(slide)}>
<h1>{slide}</h1>
</IonSlide>
))}
</IonSlides>
</IonContent>
</>
);
}
}
export default Home;
- Run
ionic serve
- Click on the “Add slides” button.
Related code:
https://github.com/m-spyratos/-ionic-react-ion-slides-adding
Other information:
Ionic info:
Ionic:
Ionic CLI: 5.2.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework: @ionic/react 0.0.6
Utility:
cordova-res: not installed
native-run: not installed
System:
NodeJS: v10.16.0 (/usr/local/bin/node)
npm: 6.10.0
OS: macOS Mojave
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:34 (1 by maintainers)
Top Results From Across the Web
bug: @ionic/react: ion-slides: Layout breaks when adding ...
When slides are being added dynamically, the layout of the slides component breaks and newly added slides sit outside of the swiper-wrapper.
Read more >reactjs - ion-slides - dynamic amount of slides - Stack Overflow
Regarding to this post, I solved it by adding a key to the IonSlides component and removing the workaround. <IonSlides ref={this.
Read more >Possible bug when dynamically updating an IonSlides ...
I've found what might be a bug when using IonSlides and dynamically appending new IonSlide components to it.
Read more >slideopts, ionic 4 slides full screen, swiper width auto, ion ...
Slides help it easy to make galleries, tutorials, and page-based layouts. ... slides are being added dynamically, the layout of the slides component...
Read more >Building Dynamic Sticky Segments with Ionic - YouTube
Learn to build a sticky segment component with Ionic that automatically changes while scrolling your lists! Learn Ionic faster with the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I faced this probelm also but I get to fix it.
I think the IonSlides did not re-initialize when prop [slides] updated from empty array.
The possible solution will be
in my case break the ionslides ui but i’ll add the key in ionslides they working fine