This is a code snippet from my Articles component:
const [articles, setArticles] = useState([]);
const [err, setErr] = useState("");
const token = sessionStorage.getItem("token");
const axiosWithToken = axios.create({
headers: { Authorization: `Bearer ${token}` },
});
const getArticles = async () => {
const res = await axiosWithToken.get("http://localhost:5000/user/articles");
if (res.data.message === "All Articles") {
setArticles(res.data.payload);
} else {
setErr(res.data.message);
}
};
useEffect(() => {
getArticles();
}, []);
This code is running without any errors. But I thought that using an arrow function with braces is too much just to run one function, so I changed the arrow function in the useEffect hook to this:
useEffect(() => getArticles(), []);
But now when I load the articles component and go to any other route the page throws an unknown error which just states that 'n' is not a function
. I don't understand why this is happening, as I see it both of them are functionally the same thing.