AnswerBun.com

How to == async axios value

Stack Overflow Asked by Jessica Bulldog on September 30, 2020

How to compare the value of the address? First returns null and then actual data

Main component

<List breed={breed} city={city} />

children

const List = ({ breed, city }) => {
...
return (
  <li  style={
    (<Adrress x={edge.node.location.lon} y={edge.node.location.lat} /> == city) ? { color: "green" } : { color: "red" }
  }>

Address component

export default function DataFteching({ x, y }) {
  const [adrress, setAdrress] = useState(null)
  const [loading, setLoading] = useState(true)
  const region = /place/
  useEffect(() => {
    async function FtechData() {
      const token = 'pk.eyJ1IjoiYW5kcmlpbXNuIiwiYSI6ImNrZGYzZ200YTJudXQyeHNjMjk2OTk2bjUifQ.njqMX6x6U946yjJdWwA7mA';
      await axios.get(`https://api.mapbox.com/geocoding/v5/mapbox.places/${x},${y}.json?access_token=${token}`)
        .then(res => {
          // console.log(res.data.features.find(place => place.id.match(region)).text)
          setAdrress(res.data)
        })
        .catch(err => console.log(err))
        .finally(() => setLoading(false));
    }
    FtechData();
  }, [])
  if (loading) return null;
  // console.log({ adrress.features.find(place => place.id.match(region)).text })
  return (adrress.features.find(place => place.id.match(region)).text)
}

Add your own answers!

Related Questions

mean(,na.rm = TRUE) returns NA and Warning Message

1  Asked on January 5, 2022 by dylan-ong

 

StringIndexOutOfBoundsException:

1  Asked on January 5, 2022 by benjamin-weed

   

How to use a promise inside a promise?

3  Asked on January 5, 2022

 

Ask in C++ code to promp user for function expression input

1  Asked on January 5, 2022 by tbaracu

     

Why does flex-basis calculation return an error in SASS?

1  Asked on January 5, 2022 by simplicius

   

Why does the ul element show when input is clicked?

1  Asked on January 5, 2022 by e-reiner

       

Why does this list element move back in the list?

1  Asked on January 5, 2022 by user13990775

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir