Trying to use react hook within cellRenderer is not allowed.
See original GitHub issueI was trying to use a react-apollo-hook in a custom cellRenderer in order to load data into a modal if the user clicks. However, I get the error message: Invalid hook call: Hooks can only be called inside of the body of a function component.
I believe it is because of the way cellRenderer is being called here.
Is there a different way to accomplish this. Or is using hooks in a cell outside of the scope of this project? Thanks for the help in advance.
For example I was trying to do something like this:
import React from 'react'
import PropTypes from 'prop-types'
import { useLazyQuery } from '@apollo/react-hooks'
import { get } from 'lodash'
import { QUERY } from './queries'
export const InterpretationsCell = ({ cellData, }) => {
const [loadDetails, { loading, data }] = useLazyQuery(QUERY)
...do something
return <p>{cellData}</p>
}
InterpretationsCell.propTypes = {
column: PropTypes.shape({
variantType: PropTypes.string.isRequired,
idKey: PropTypes.string.isRequired,
}).isRequired,
}
export default InterpretationsCell
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
react hook useState in AgGridColumn onCellClicked function
Here is the problem: if I want to use my state get/set ( useState hook) inside of the onCellClicked function it is not...
Read more >Customising React Data Grid with Hooks and Functions
AG Grid supports customisation through components written in React with both classes and hooks. Learn how to use functional hook components.
Read more >Rules of Hooks - React
Don't call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function, before any...
Read more >Customising Cells with React Components as Cell Renderers
Customising cells using React Cell Renderers, these are simple functions that return JSX to add your own React component to format and add ......
Read more >ag-Grid Components: Cell Renderers
Use Cell Rendering to have cells rendering values other than simple strings. ... If you do not want to handle the refresh in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@genomics-geek fixed in v1.7.2
@genomics-geek I’d say that would be problematic if you use local state in cell renderer, as the component will be unmount when it’s out of viewport by scrolling, and all the local state will be lost, from your snippet, I think you can use
onRowsRendered
to perform lazy data loading, and that’s what we did internally, by that way you can load and cache on demand