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.

[Browser] Virtualized swipeable views unmount and remounts all children on each swipe

See original GitHub issue

When trying the example on the readme, I noticed that at each swipe all views with an index in range for being rendered were unmounted and remounted. I would only expect the last view to be mounted and the first one to be unmounted. All other should at most be updated.

Here is a slighly modified example that logs component mounting and unmounting. And below is the output I get as I swipe from index number 4 to index number 5.

import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import SwipeableViews from 'react-swipeable-views';
import {virtualize} from 'react-swipeable-views-utils';
const VirtualizeSwipeableViews = virtualize(SwipeableViews);
class Slide extends Component {
    componentDidMount() {
        console.log(this.props.index, 'did mount');
    }
    componentWillUnmount() {
        console.log(this.props.index, 'will unmount');
    }
    render() {
        const index = this.props.index;
        return <div>{`slide n°${index}`}</div>;
    }
}

const slideRenderer = ({key, index}) => {
    return (
        <Slide key={key} index={index} />
    );
};

const node = document.getElementById('app');
const root = <VirtualizeSwipeableViews slideRenderer={slideRenderer} />;
ReactDOM.render(root, node);

image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bmueller-sykescommented, Dec 7, 2017

Oh, right! I’m so sorry! I get it now. Thanks so much for your patience.

0reactions
oliviertassinaricommented, Dec 7, 2017

then I get 6 SLIDE MOUNT declarations when VirtualizeSwipeableViews first loads. Is that expected?

@bmueller-sykes Yes, It’s. We prerender the slides forward and backward.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage - react-swipeable-views
Usage. Get started with react-swipeable-views in no time. Simple example. usage. Browser. import React from 'react'; import SwipeableViews from ...
Read more >
How to use the react-swipeable-views-utils.virtualize function ...
To help you get started, we've selected a few react-swipeable-views-utils examples, based on popular ways it is used in public projects.
Read more >
Avoid unnecessary remounting of DOM elements in React
I ran into a strange problem while trying to use React's built-in animation API to fade in/out DOM elements when they enter/exit the...
Read more >
React Autocomplete/Dropdown/Select Components – downshift
The plan is to create each hook in that repo, test it against Downshift ... be the cool kid from the future that...
Read more >
Untitled
Find a one-night stand or a hookup you can also hang out with. Which dating site is best for serious relationships? What is...
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