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

133
Visualizações
Object formatting in React.js

Im trying to render a component that returns the description of an item from an api. In this instance i'm returning spells from the DnD API, and trying to access the url for each one to display their descriptions.So far i have the endpoints for the dropdown menus working correctly. Im trying to format whats being returned into another endpoint to use with my description component.I have a state called "selectedSpell" that tracts what used in the dropdown. right now i'm only getting an object that i cant figure how to turn into the string i want. I hope im making sense with what i want to do 😓

heres what i have working.

import {useState , useEffect} from 'react'
import axios from 'axios';

export default function Description (props){
const { selectedSpell } = props
console.log(props)

const [description, setDescription] = useState([]);
    const fetchDesc = async () => {
      try {
        const DESC_URL = "{https://www.dnd5eapi.co/{props.selectedSpell}";
        const response = await axios.get(DESC_URL);
        console.log("response", response.data.results);
          setDescription(response.data.results);
          console.log(description)
      } catch (error) {
        console.log(error);
      }
    };
    useEffect(() => {
      fetchDesc();
    }, []);
    return(
        <div>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
                Consectetur nunc, morbi enim, rhoncus lacus duis. 
                Tortor amet pulvinar dolor fringilla sit elit ac ut. 
            </p>
        </div>

    )

}

im new here and cant post images yet lol

https://i.stack.imgur.com/iqi9Y.png

Im trying to get that description module to return an api call based off what "spell" is chosen

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You got a few problems here.

DESC_URL

The URL you got there will let your app request to

/%7Bhttps://www.dnd5eapi.co/%7Bprops.selectedSpell%7D

on your local machine. const DESC_URL = https://www.dnd5eapi.co/${props.selectedSpell}; is what your looking for. Im not sure what happend there.

The API itself

I will suggest you read their Documentation. There is a woring url with example response on there.

about 4 years ago · Juan Pablo Isaza 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