0
I’m having a problem with a project I’m using React.js, and axios for consumption of API
const [id, setId] = useState('');
const [image, setImage] = useState('');
const [att, setAtt] = useState(0);
const [nameCorrect, setNameCorrect] = useState('');
const [type, setType] = useState([])
useEffect(() => {
api.get(props.name)
.then(res => {
setId(res.data.id);
setImage(res.data.sprites.front_default);
setType(res.data.types)
setNameCorrect(props
.name
.substring(0,1)
.toUpperCase()
.concat(props.name.substring(1))
);
})
On the line of setType(res.data.types) basically is not guarding the array with the data in constante type
This is the link of the api I’m using, if you notice have types within the date I’m looking for https://pokeapi.co/api/v2/pokemon/1/
Note: when giving a console.log in the types he returns arrays empty.
It depends on where you are giving console.log in to
type, if it’s inside theuseEffectthat runs non-stop will never see any update.– novic