been getting errors trying to get the url hostname from the response of the API even after I try to JSON.stringify the url since it works ok when I use a regular typed out url, any way of getting around this?
the error I get is Uncaught TypeError: Failed to construct 'URL': Invalid URL
const Articles = props => {
const [article, setArticle] = useState([]);
useEffect(() =>{
axios.get(`https://example.com/item/${props.source}.json`)
.then((response)=>{
console.log(response)
setArticle(response.data)
})
}, [])
let articleUrl = JSON.stringify(article.url)
const url = new URL(articleUrl);
return(
<div>
<h1>{article.title}</h1>
<a href={article.url}>
<p>{url.hostname}</p>
</a>
</div>
)}
export default Articles