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.

Keep current page index when changing state?

See original GitHub issue

I’m using Swiper and on the second page there is a textinput. When the user changes the text in the textinput I call setState() to update the state with the changes. The problem is, when the state reloads, Swipe automatically shows the first page not the second page. I’ve tried to set the index prop on Swipe but it doesn’t seem to work correctly. Any way to keep the current page when updating the state?

<TextInput
    onChangeText={(name) => {this.setState({name})}}
    value={this.state.name} />

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

4reactions
wgormleycommented, Jan 28, 2016

my way might not work for your use cases but this is what i did. i set a state variable in my constructor: this.state = { someOtherStuff: 2, cameraIndex: 1 }; set the index in the swiper to this variable index={this.state.cameraIndex} then when i change the state, i make sure to set this state variable self.setState({someOtherStuff: val, cameraIndex: 0}) feels a bit hacky but its working for me for now

1reaction
L-Jovicommented, Mar 21, 2016

now I use _onMomentumScrollEnd(e, state, context) reset current index, it works.

regards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maintaining GridView current page index after navigating ...
I am looking for sample code snippet on the Server Side on how to specify the page index to set the GridView after...
Read more >
How can I set pageIndex of paginator and it can update itself?
First page is 0 and current page is 1, the paginator view display 11-20 of 400 . I set the pageIndex to initial...
Read more >
Create and update an index - Microsoft Support
To edit or format an index entry, change the text inside the quotation marks. To update the index, click the index, and then...
Read more >
page.info() - DataTables
This method provides information about the table's paging state, and information about the number of records in the table (both total and in...
Read more >
Oregon.gov : State of Oregon
The official homepage of the State of Oregon.
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