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

273
Views
¿Cómo hago aparecer un error de reaccionar nativo?

Tengo un componente funcional donde llamo a un método desde otro archivo .js. El método dentro del archivo .js arroja un error (que está bien, para mis propósitos de prueba), pero quiero que este error llegue al método dentro del componente funcional. ¿Cómo puedo hacer eso?

 import { pickImageAsync, } from "./someFile"; export default class Component1 extends React.Component<any> { render() { const { sendError } = this.props; function pickImage() { try { //calling from another file pickImageAsync(onSend); } catch (error) { //I dont reach this part of the file console.log("I am catching error: ", error); sendImageError(true); } }

En mi archivo someFile.js :

 export async function pickImageAsync(onSend) { if (await getImagePickerPermissionAsync()) { let result; try { //with the way I test it this method throws the error, which I want to bubble up result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, quality: 1, }); //with the way I test it, I dont see any result, which is OK for my testing purposes console.log(result); // I dont reach this peace of code which is fine if (!result.cancelled) { onSend([{ image: result.uri }]); } } catch (error) { //I am catching the error and I see it on the console, but how do I bubble it up? console.log("could not select image: ", error); } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe throw este error ( throw error ). Esto hará que aparezca en la pila de llamadas hasta que alguien lo atrape (o no, y verá un error en la consola).

Mira la última línea que agregué:

 export async function pickImageAsync(onSend) { if (await getImagePickerPermissionAsync()) { let result; try { //with the way I test it this method throws the error, which I want to bubble up result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, quality: 1, }); //with the way I test it, I dont see any result, which is OK for my testing purposes console.log(result); // I dont reach this peace of code which is fine if (!result.cancelled) { onSend([{ image: result.uri }]); } } catch (error) { //I am catching the error and I see it on the console, but how do I bubble it up? console.log("could not select image: ", error); throw error; } } }
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!