So I have a block of code the effectively is taking the url and translating that to a request to an Open API.
The issue is that for whatever reason my axios.get seems to be executed twice. Relatively new developer in React and I I am guessing I am overlooking something fundamental.
Any advice would be greatly received. Thanks in advance.
import React, { useEffect, useState } from "react";
import axios from 'axios';
import {useParams} from 'react-router-dom';
import configData from './config/config.json'
const Article = () => {
console.log('0')
const requestarticle = useParams();
console.log('1')
const [url] = useState(configData.BACKEND_URL + '/articles/' + requestarticle.page)
console.log('2')
const [article, setArticle] = useState(null)
console.log('3')
useEffect(() => {
console.log('4')
axios.get(url)
.then(Response =>
{setArticle(Response.data)}
)
}, [url])
if (article){
return (
<>
<div id="page-content" dangerouslySetInnerHTML={{__html: article.content}} class="container-sm text-start border border-dark rounded border-3"></div>
</>
);
}
return(
<h1> NOTHING TO RETURN</h1>
)
}
export default Article ;