react-base-table icon indicating copy to clipboard operation
react-base-table copied to clipboard

rowRenderer invalid hooks error

Open aselcuk opened this issue 4 years ago • 3 comments

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.

aselcuk avatar Jun 13 '21 16:06 aselcuk

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.

cph0 avatar Jun 13 '21 16:06 cph0

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

aselcuk avatar Jun 13 '21 17:06 aselcuk

@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

nihgwu avatar Jun 13 '21 18:06 nihgwu