Skip to content

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

Merged
jfilter merged 2 commits into
jfilter:masterfrom
lowewenzel:master
Oct 29, 2018
Merged

Add givePageIndex() to provide the index of the scrolled page to a prop function#40
jfilter merged 2 commits into
jfilter:masterfrom
lowewenzel:master

Conversation

@lowewenzel
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants