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

269
Views
desestructuración de objetos en react-create-app

En un archivo llamado index.js tengo la siguiente exportación:

 export default { foo: true, bar: false }

Más tarde en el archivo home.js estoy haciendo lo siguiente:

 import { foo, bar } from './index' console.log(foo, bar) -> undefined, undefined

Si importo todo como:

 import index from './index' console.log(index) -> { foo: true, bar: false }

¿Alguien puede explicarme por qué sucede esto? ¿Estoy haciendo algo mal?

Estoy usando:

› crear-reaccionar-aplicación -V 1.0.3

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Lo que tienes allí se llama exportaciones , no desestructuración.

Tienes que exportarlos como tales, no como una exportación predeterminada :

 // this will export all of the defined properties as individual // named exports, which you can pick-and-choose when importing // using a similar syntax to destructuring const foo = true, bar = false; export { foo, bar } // imported exports named 'foo' and 'bar' import { foo, bar } from './my-file'.

Si especifica una exportación default , lo que siga a la palabra clave default se exportará cuando importe sin llaves:

 // this exports an object containing { foo, bar } as the default export export default { foo: true, bar: false } // imported without {} import objectContainingFooBar from './my-file';
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!