how to pass props within constants in React-Native

Asked

Viewed 17 times

0

Hi, I’m developing an app in React Native and I have this convert function that gets 3 props(code, codein and name) they all get a String and I want to put the prop code in place of USD, so it changes along with the prop but when I put for example: const cotacao = response.data.code.ask;

he gives the error:

[Unhandled Promise rejection: Typeerror: Undefined is not an Object (evaluating 'Response.data.code.Ask')]

This is the code, is small because I removed the codes that are not part of the question...

export function Converter({code, codein, name}) {
  const [moedaA, setMoedaA] = useState(code);
  const [moedaB, setMoedaB] = useState(codein);


  async function converter() {
    const response = await api.get(`json/all/${code}-${codein}`);
    const cotacao = response.data.USD.ask;        // mudar aqui
    setVariant(response.data.USD.pctChange);      // mudar aqui

    if (response.data.USD.pctChange > 0) {        // mudar aqui
      setColorVariant('#ffff00');
      setVariantIconName('arrowup');
    } else if (response.data.USD.pctChange < 0) { // mudar aqui
      setColorVariant('#ff0000');
      setVariantIconName('arrowdown');
    }

  return (
    <View style={styles.container}>
      // retorna algo
    </View>
  )
}```
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.