Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

rowRenderer invalid hooks error #312

Open
aselcuk opened this issue Jun 13, 2021 · 3 comments
Open

rowRenderer invalid hooks error #312

aselcuk opened this issue Jun 13, 2021 · 3 comments

Comments

@aselcuk
Copy link

aselcuk commented Jun 13, 2021

I used rowRenderer for my custom row component and ı need to use useEffect hooks inside this component but ı got Invalid hook call error.

...
      <AutoResizer>
        {({ width, height }) => (
          <Table
            data={events}
            width={width}
            height={height}
            onEndReached={handleEndReached}
            headerRenderer={<BulletinHeader eventsTotalCount={eventsTotalCount} />}
            rowRenderer={EventRow}
            rowHeight={84}
          />
        )}
      </AutoResizer>
...

if ı use the hooks inside EventRow component ı got react.development.js:1476 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. error.
EventRow is a functional component.

@cph0
Copy link

cph0 commented Jun 13, 2021

You can pass an inline function to the rowRenderer prop like this:

rowRenderer={props => <EventRow {...props} />}

You shouldn't get the invalid hooks error in this case.

@aselcuk
Copy link
Author

aselcuk commented Jun 13, 2021

@cph0 thanks for solution ı applied it but ı think still this is an issue.

@nihgwu
Copy link
Contributor

nihgwu commented Jun 13, 2021

@aselcuk Hey, that's because if it's a function, it will be invoked directly instead of React.createElement for performance reason, and that is made before React Hooks are created, in the next major version, it will always be treated as a component

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

No branches or pull requests

3 participants