0

I have a problem, the steam api returns content as html code even though my headers are set to "application/json" as well as the formatting is correct in the url parameters. I've accepted that the link is correct, and Steam just returns html code in the "contents" property. I've sent the length to 300 because I want to return a brief description, and I feel like 300 is a length. As you can see here,

http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=72850&count=3&maxlength=300&format=json

inside appnews.newsitems.contents that it's all html. I don't know what's going to be new inside the code. so it's very well possible that the string that is returned is something like <a href=\"https://www.modiph... in the middle of html code. Is there any way to solve with without some insane crazy crazy regex?

  • Can you provide us an example of what you've linked to? I'm unable to view it, firstly, and secondly it's best to put everything within your question. – zfrisch May 20 '19 at 20:03
  • Sure, I thought it would be easy to see. `"contents": "If you've got an itch for more adventures in Skyrim, you'll soon be able to delve into draugr-infested crypts and fight in the civil war on your table. The Elder Scrolls: Call to Arms is a tabletop miniature adaptation where you'll lead followers into dungeons and battles with diminut...",` this is what's being returned – brandon.joe May 21 '19 at 05:00

1 Answers1

0

You can make use of dangerouslySetInnerHTML function to set the content of react element to JSX.

From the docs.

function createMarkup() {
  return {__html: 'First &middot; Second'};
}

function MyComponent() {
  return <div dangerouslySetInnerHTML={createMarkup()} />;
}

Further reading: https://reactjs.org/docs/dom-elements.html

Anshul Bansal
  • 1,833
  • 1
  • 13
  • 12
  • Thanks, but that doesn't solve the problem when I am being sent back html code that could be truncated because of the 300 character limit. But this is a good start if I can someone guarantee that the result would have full and complete html code to render. – brandon.joe May 21 '19 at 05:02