Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
Possible Unhandled Promise Rejection (id: 0) react-native-text-recognition

I tried to add the try / catch method but to no use, maybe I added it in a wrong manner?


Objective: Open camera and scan an image for text, if it has any, the text will display below 'Text Recognition'


The only place where I wrote code was in App.js :

import React, {useEffect, useState} from 'react';
import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
import TextRecognition from 'react-native-text-recognition';

import {
  SafeAreaView,
  StatusBar,
  Text,
  View,
} from 'react-native';

const App = () => {
  const [image, setImage] = useState(null);
  const [text, setText] = useState(null);

useEffect(() => {
  launchCamera({}, setImage); //launch camera (active)
}, []);

// useEffect(() => {
//   launchImageLibrary({}, setImage); //i can launch library using this
// }, []);

useEffect(() => {
  (async () => {
  if (image) {
    const result = await TextRecognition.recognize(image.assets[0].uri);

    console.log(result);

    setText(result);
  }
  })();
},[image]);

  return (
    <SafeAreaView>
      <StatusBar>
        <View>
          <Text>Text Recognition</Text>
            {text ? <Text>{text}</Text> : null}
        </View>
      </StatusBar>
    </SafeAreaView>
  );
};

export default App;

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Try wrapping the await TextRecognition.recognize(...) call with a try/catch:

useEffect(() => {
  (async () => {
  if (image) {
    try {
      const result = await TextRecognition.recognize(image.assets[0].uri);

      console.log(result);

      setText(result);
    } catch (error) {
      console.error(error);
    }
  }
  })();
},[image]);
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda