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.

onIndexChanged produces Warning: Cannot update a component from inside the function body of a different component.

See original GitHub issue

Which OS ?

iOS

Version

Which versions are you using:

  • react-native-swiper v1.6.0
  • react-native v0.63.2

Expected behaviour

No errors/warnings?

Actual behaviour

This code produces a warning, Warning: Cannot update a component from inside the function body of a different component..

import React, {useState} from 'react';

import Swiper from 'react-native-swiper';

const [swiperIndex, setSwiperIndex] = useState(0);

const testComponent = () => {
  return <Swiper style={styles.wrapper} onIndexChanged={(i) => setSwiperIndex(i)}>
}

export default testComponent;

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:36
  • Comments:26

github_iconTop GitHub Comments

20reactions
ManhVuTiencommented, Nov 3, 2020

I use onIndexChanged={(newIndex) => { setTimeout(() => { setIndex(newIndex); }, 1); }} The warning is gone.

11reactions
dbenfouzaricommented, Aug 20, 2020

Ugh, I just went away from this package and used react-native-snap-carousel instead. Sorry guys.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update a component from inside the function body of a ...
I am getting error as below. Warning: Cannot update a component from inside the function body of a different component. How to remove...
Read more >
How to fix the "cannot update a component while rendering a ...
A quick guide to how I solved a confusing React error.
Read more >
Cannot update a component while rendering a different ...
Here's what happened and how to fix it. In my case the message looked like this: Warning: Cannot update a component (`ForwardRef( ...
Read more >
How I fixed 'Cannot update a component from inside the ...
In this short article I highlight why 'Cannot update a component from inside the function body of a different component' warning happened in ......
Read more >
Building the Confluent UI with React Hooks – Benefits and ...
Warning : Cannot update a component from inside the function body of a different component. Wrapping dispatch / setState with useEffect solves ...
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