Hi I hope the title is enough to understand my problem. There is no error when exporting data, I just want that if the checkbox is unchecked or false it will hide the excel column of excel when exported. And if the checkbox is checked or true it will display or show the excel column when the excel is exported.
const [filteredData, setfilteredData] = useState(false)
const [checked, setChecked] = React.useState(false);
const handleDisplay = (event) => {
console.log(event.target.checked)
setChecked(event.target.checked);
}
....,
<Checkbox checked={checked} onChange={handleDisplay} /> Display Name<br></br>
<ExcelExported exportClass={'admin-add-btn'} filteredData={filteredData} checked={checked}></ExcelExported>
ExcelExported.js
import React from 'react'
import ReactExport from 'react-export-excel'
import { Button } from '@material-ui/core'
const ExcelFile = ReactExport.ExcelFile
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;
const ExcelColumn = ReactExport.ExcelFile.ExcelColumn;
function ExcelExported(props) {
const { exportClass, filteredData, checked } = props
console.log(checked)
const fileNameFormatted = 'Student Information'
return (
<div>
<ExcelFile filename="Student Information" element={
<Button style={{ textTransform: 'none', minWidth: '240px' }}
className={exportClass}
variant='contained'
// onClick={handlePrint}
>
Export
</Button>
}>
<ExcelSheet data={filteredData} name="Users" >
<ExcelColumn label="Student Name" value="name" hide={checked}/>
</ExcelSheet>
</ExcelFile>
</div >
)
}
export default ExcelExported
this is my https://www.npmjs.com/package/react-export-excel library for exporting excel sheet
what i've tried so far is putting hide={checked} there is no error but even the checkbox is unchecked, it display the column, and i also tried this
{checked ? (<ExcelColumn label="Student Name" value="name")/>:(null)}
and i received this error

{checked ? (<ExcelColumn label="Student Name" value="name"):(null)}it seems like you are not closing the<ExcelColumntag anywhere ( you are missing the/>aftervalue="name") . Also if that isn't the issue, maybe you could edit an existing sandbox like codesandbox.io/s/wrdew to give a minimal reproducible example :)