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.

Updating state onChanged causes tons of logs

See original GitHub issue

I have a problem while trying to set the current active slide index on carousel changed onChanged. I’m passing this state down the slide, but when I update the slider state it simply reaches the maximum call stack of JS.

I have the following structure:

<Carousel>
    <Slide currentSlideIndex={this.state.currentSlideIndex}/>
    <Slide currentSlideIndex={this.state.currentSlideIndex}/>
</Carousel>

The thing is that the carousel if going to be controlled by each Slide, since there is some video I want to play, therefore I am planning to use the next() method.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
joshuadiezmocommented, Aug 30, 2017

I create separate component and add shouldComponentUpdate

class ImagePreview extends Component {
	shouldComponentUpdate(nextProps, nextState) {
		return false;
	}

	render() {
		return (
			<div>
				<OwlCarousel
					className="owl-theme"
					loop margin={10} nav autoplay items={1}
				>
					<div class="item"><h4>1</h4></div>
					<div class="item"><h4>2</h4></div>
					<div class="item"><h4>3</h4></div>
					<div class="item"><h4>4</h4></div>
					<div class="item"><h4>5</h4></div>
					<div class="item"><h4>6</h4></div>
					<div class="item"><h4>7</h4></div>
					<div class="item"><h4>8</h4></div>
					<div class="item"><h4>9</h4></div>
					<div class="item"><h4>10</h4></div>
					<div class="item"><h4>11</h4></div>
					<div class="item"><h4>12</h4></div>
				</OwlCarousel>
			</div>
		);
	}
}
3reactions
adriancmirandacommented, Mar 1, 2019

I made something very similar to @joshuadiezmo

import React from 'react';
import ReactOwlCarousel from 'react-owl-carousel';
import 'owl.carousel/dist/assets/owl.carousel.css';
import 'owl.carousel/dist/assets/owl.theme.default.css';

export default class OwlCarousel extends React.Component {
	shouldComponentUpdate() {
		return false;
	}

	render() {
		const { children, ...props } = this.props;
		return (
			<ReactOwlCarousel {...props}>
				{children}
			</ReactOwlCarousel>
		);
	}
}

that works like a charm

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating state onChanged causes tons of logs #21 - GitHub
I have a problem while trying to set the current active slide index on carousel changed onChanged. I'm passing this state down the...
Read more >
setState doesn't update the state immediately - Stack Overflow
It means you can't call it on one line and assume the state has changed on the next. According to React docs. setState()...
Read more >
Why React doesn't update state immediately - LogRocket Blog
When developing React applications, you may have noticed that state updates don't immediately reflect new values after being changed.
Read more >
Common Mistake with Synchronizing State in React -- newline
If some state is updating half way through a render, it may cause unexpected and difficult to debug changes to some other area/state....
Read more >
What Every React Developer Should Know About State
If we were to log our newly updated state as we type into our form, ... our state is updated, and this causes...
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