I'm using a react hook component with antd. When setting up columns for a table, the render function is giving me an ESLint error:
ESLint: Component definition is missing displayName (react/display-name)
I've tried adding displayName to the object but this doesn't work.
This is the code:
const columns_payment_summary_table = [
{
title: SettlementConstants.LABEL_QUANTITY_SELECTED,
dataIndex: 'group',
key: 'group',
render: text => (
<span>{getCountForCountry(text)}</span>
),
}
]
Can anyone help?
Here is full component code (well just the relevant bits)
import * as SettlementConstants from './constants'
import {connect} from 'react-redux'
import React, {useState, useEffect} from 'react'
import {Card, Table} from 'antd'
import PropTypes from 'prop-types'
const propTypes = {
settlements: PropTypes.object.isRequired,
}
function Settlements(props) {
const [selectedSettlementRows, setSelectedSettlementRows] = useState([])
useEffect(() => {
getSettlementDetails()
}, [])
function getSettlementDetails() {
props.dispatch({
type: SettlementConstants.GET_SETTLEMENT_PAYMENT_SUMMARIES,
params: {
'group_by': 'country_code',
'type': SettlementConstants.CLAIM_SETTLEMENT,
}
})
props.dispatch({
type: SettlementConstants.GET_SETTLEMENT_PAYMENTS,
params: {'type': SettlementConstants.CLAIM_SETTLEMENT, }
})
}
const columns_payment_summary_table = [
{
title: SettlementConstants.LABEL_QUANTITY_SELECTED,
dataIndex: 'group',
key: 'group',
render: text => (
<span>{getCountForCountry(text)}</span>
),
}
]
function getCountForCountry(country_code){
let selected_country = selectedSettlementRows.filter(function(row){
return row.group === country_code
})
if(selected_country && selected_country.length > 0){
return selected_country[0].ids.length
} else {
return 0
}
}
return (
<div>
<Card
title={SettlementConstants.LABEL_SETTLEMENT_SUMMARY}>
<Table
columns={columns_payment_summary_table}
bordered={true}
dataSource={props.settlements.settlement_payment_summaries}
loading={props.settlements.settlement_payment_summaries_pending && !props.settlements.settlement_payment_summaries}
rowKey={record => record.group}
/>
</Card>
</div>
)
}
Settlements.propTypes = propTypes
const mapStateToProps = (state) => {
return {settlements: state.settlementsReducer}
}
export default connect(
mapStateToProps,
)(Settlements)
ESLint thinks you are defining a new component without setting any name to it.
This is explained because ESLint cannot recognize the render prop pattern because you are not directly writing this render prop into a component, but into an object.
You can either put the render
prop directly into your jsx implementation of the <Column>
component, or shut down the ESLint's error by doing this :
const columns_payment_summary_table = [
{
title: SettlementConstants.LABEL_QUANTITY_SELECTED,
dataIndex: 'group',
key: 'group',
// eslint-disable-next-line react/display-name
render: text => (
<span>{getCountForCountry(text)}</span>
),
}
]
I hope it helped ;)