Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

394
Vistas
How to get JSX in an object from a function finding data (JSX) through another file?

I want to get JSX in an object (foundCategory) from another file categoriesDetails, by using the find funtion through checking the item.title. Below is my code

Here How I m retrieving and want to send data as props to a component (CategoryDetails).

import type { NextPage } from 'next';
import CategoryDetails from '../components/CategoryDetails.jsx'
import {categoryDetails} from '../utils/categoriesDetails'

const Home: NextPage = () => {

  let foundCategory = null;
  foundCategory = categoryDetails.find(function(item){
    return item.title === 'Bus Plugs'
  })
  console.log(foundCategory)
  
  return (
    <>
      <Header />
      {foundCategory ? <CategoryDetails
            oDetails={foundCategory.details}
            sTitle={foundCategory.title}
          /> : ''
      }
      <FooterBar/>
    </>
  )
}

export default Home

and Here is my categoriesDetails.js from which I m exporting categories data (Simplified)

export const categoryDetails = [
  {
    title: 'Bus Plugs',
    details: (
          <div>
              <ul> </ul>
              <img src={`${categoryImagesDir}bus-plugs-large.jpg`} />
          </div>
       )
  },
  {
    title: 'Fuse',
    details: (
          <div>
              <ul> </ul>
              <img src={`${categoryImagesDir}fuse-large.jpg`} />
          </div>
       )
  }

But when I console to check, I get the following result instead the actual JSX in foundCategory.details. which I want to use in child component (CategoryDetails).

{
  title: 'Bus Plugs',
  details: {
    '$$typeof': Symbol(react.element),
    type: 'div',
    key: null,
    ref: null,
    props: { children: [Array] },
    _owner: null,
    _store: {}
  }
}

Looking forward, thanks

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In your Home component, you have this code:

 foundCategory = categoryDetails.find(function(item){
   return item.title = 'Bus Plug'
 })

item.title = "Bus Plug" doesn't check for equality, it sets item.title to "Bus Plug". you have to change this line to this:

 return item.title === 'Bus Plug'
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try rewriting item.details to a function:

details: () => (
  <div>
      <ul></ul>
      <img src={`${categoryImagesDir}fuse-large.jpg`} />
  </div>
)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda