Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
createRef().current viene como nulo en React

básicamente, mi caso de uso es que cuando hago clic en el botón de descarga presente en cada fila de la tabla, mis datos devueltos deben descargarse a través de CSV. Estoy creando la referencia así

 class ViewStorageGroups extends Component { csvLink = React.createRef();

Este es mi componente personalizado que representa una tabla

 <TableWithHeaders tableHeaders = {tableData.tableHeaders} rowData = {tableData.rowData} formatter = {tableData.formatter} handleClick = {this.handleClick} clickable = {tableData.clickable} page = {rowsPerPage} rowsPerPage = {rowsPerPage} handlePageChange = {this.handlePageChange} handleChangeRowsPerPage = {this.handleChangeRowsPerPage} />

esta es mi función handleClick que se llama cuando presiono el botón de descarga

 handleClick = (rowData, clickComponent,e) => { const storageGroupDto = StorageGroupHelpers.convertStorageGroupDataToDto(rowData) this.setState({groupDataDownloadResp: storageGroupDto}, () => this.csvLink.current.link.click()) }

y estoy usando el componente CSVLink de React para descargar los datos como csv.

 renderDownloadedData = () => { const fileName = createFileNameForCSVDownload('STORAGE_GROUP_DOWNLOAD', getWarehouseIdFromRedux(this.props)) return ( <div> <CSVLink ref={this.csvLink} data={this.state.groupDataDownloadResp} filename={fileName} target='_blank' /> </div> )

} Ahora, el problema es que cuando se activa handleClick, mi this.csvLink.current aparece como nulo. la misma implementación está presente en otros lugares de mi base de código y funciona correctamente. No puedo averiguar dónde me estoy equivocando. También intenté inicializar csvLink = React.createRef(); en componenteDidMount y el constructor, pero sigue ocurriendo el mismo error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

finalmente obtuve el problema pero no estoy seguro de la razón. si uso

 <CSVLink ref={this.csvLink} data={this.state.groupDataDownloadResp} filename={fileName} target='_blank' />

dentro de una función de flecha como esta

 renderDownloadedData = () => { const fileName = createFileNameForCSVDownload('STORAGE_GROUP_DOWNLOAD', getWarehouseIdFromRedux(this.props)) return ( <div> <CSVLink ref={this.csvLink} data={this.state.groupDataDownloadResp} filename={fileName} target='_blank' /> </div> ) }

y luego llamar a este render interior como este

 render () { return ( {this.renderDownloadedData()} ) }

Devuelve el valor actual de reactRef() como nulo. sin embargo, si no uso la función de flecha y uso la función como esta renderDownloadedData () , funciona perfectamente bien. si alguien me puede explicar la razon se lo agradeceria mucho

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!