onIndexChanged produces Warning: Cannot update a component from inside the function body of a different component.
See original GitHub issueWhich 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:
- Created 3 years ago
- Reactions:36
- Comments:26
Top 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 >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 FreeTop 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
Top GitHub Comments
I use
onIndexChanged={(newIndex) => { setTimeout(() => { setIndex(newIndex); }, 1); }}
The warning is gone.Ugh, I just went away from this package and used
react-native-snap-carousel
instead. Sorry guys.