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

657
Views
¿Cómo agregar una etiqueta <br> en reactjs entre dos cadenas?

Estoy usando reaccionar. Quiero agregar un salto de línea <br> entre cadenas

'Sin resultados' y 'Intente con otro término de búsqueda'.

Intenté 'No results.<br>Please try another search term.'

pero no funciona, necesito agregar el <br> en el html.

¿Alguna idea de cómo resolverlo?

 render() { let data = this.props.data; let isLoading = this.props.isLoading; let isDataEmpty = Object.entries(data).length === 0; let movieList = isLoading ? <Loader /> : isDataEmpty ? 'No results. Please try another search term.' : Object.entries(data).map((movie, index) => <MovieTile key={index} {...movie[1]} />); return ( <div className='movieList'>{movieList}</div> ); }

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Deberías usar JSX en lugar de una cadena:

 <div>No results.<br />Please try another search term.</div>

Debido a que cada jsx debe tener 1 contenedor, agregué un contenedor <div> para la cadena.

Aquí está en su código:

 render() { let data = this.props.data; let isLoading = this.props.isLoading; let isDataEmpty = Object.entries(data).length === 0; let movieList = isLoading ? <Loader /> : isDataEmpty ? <div>No results.<br />Please try another search term.</div> : Object.entries(data).map((movie, index) => <MovieTile key={index} {...movie[1]} />); return ( <div className='movieList'>{movieList}</div> ); }
over 4 years ago · Santiago Trujillo Report

0

Puede usar espacios en blanco CSS para resolver el problema.

Reaccionar componente

 render() { message = `No results. \n Please try another search term.`; return ( <div className='new-line'>{message}</div> ); }

CSS

 .new-line { white-space: pre-line; }

PRODUCCIÓN

 No results. Please try another search term.
over 4 years ago · Santiago Trujillo Report

0

dividir texto en línea:

 render() { ... <div> {this.props.data.split('\n').map( (it, i) => <div key={'x'+i}>{it}</div> )} </div> ...
over 4 years ago · Santiago Trujillo 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!