Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!