'Fetch json data from url

I am new to REACT and I was trying to learn how to get and display a specific parameter from a json style message stored in an url.

I have this json style:

{
        "id":1,
        "color":"blue",
        "backgroundColor": "#44014C",
        "details":[
            {
                "width": "155px",
                "height": "150px",
                "type": "Brand logo"
            }
        ]
    },
    {
        "id":2,
        "color":"yellow",
        "details":[
            {
                "width": "100px",
                "height": "100px",
                "type": "Brand logo"
            }
        ]
    }

and i have dynamic url each url have own style i used this but don't work with me

[enter image description here][1] Please someone can help me?

  const { slug } = useParams()

  const [style, setStyle] = useState([]);
  
  useEffect(()=>{
    setStyle(Style[0])
  },[Style.id])

  useEffect(() => {
      const getstyle = () => {
          const json = Style
          setStyle(json);
      };
      getstyle(slug);
  }, [slug]);



          {Style.map( (item)=>{
              <div key={item.id} className={item.backgroundColor}>
                 <h1>Hello {slug} </h1>
              </div> 
              console.log (item.backgroundColor);
        })}


Solution 1:[1]

Does this json comes in body of response ?

Also it may look like json, but if you cannot access it try to parse body before

also try this package to send requests to endpoints instead of useFetch.

https://www.npmjs.com/package/axios

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matic Stare