Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add givePageIndex() to provide the index of the scrolled page to a prop function #40

Merged
merged 2 commits into from
Oct 29, 2018
Merged

Conversation

lowewenzel
Copy link
Contributor

Example usage:

...
getPageIndex = (pageIndex) => {
  this.setState({
    pageIndex,
  });
}

render() {
  return (
    <Onboarding givePageIndex={this.getPageIndex}
       ...

@jfilter jfilter merged commit b8713c1 into jfilter:master Oct 29, 2018
@jfilter
Copy link
Owner

jfilter commented Oct 29, 2018

Thanks for your work!

I renamed the prop to pageIndexCallback. The full example is then:

...
getPageIndex = (pageIndex) => {
  this.setState({
    pageIndex,
  });
}

render() {
  return (
    <Onboarding pageIndexCallback={this.getPageIndex}
       ...

@jfilter jfilter mentioned this pull request Oct 29, 2018
@ilbertt
Copy link

ilbertt commented Jul 1, 2021

I have a problem with this callback.
My code:

const [pageIndex, setPageIndex] = useState(0);

const changePageHandler = (index) => {
    setPageIndex(index);
}

<Onboarding pageIndexCallback={changePageHandler}
       ...
/>

I get this warning:

Warning: Cannot update a component from inside the function body of a different component.
at [native code]:null in dispatchAction
at screens/StartScreen.tsx:74:8 in StartScreenComponent
at [native code]:null in performSyncWorkOnRoot
at [native code]:null in callFunctionReturnFlushedQueue

I also tried to wrap changePageHandler in a useCallback hook, but the warning persists.

@lucidprojects
Copy link

I have the same problem as @Luca8991. Did anyone find a solution?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants