I requested for a file from a POSTGRES DB through a get request so I can render in my react application, but react renders it as normal string instead of html element or JSX.
In the code I stored the file in a redux store which I later passed as props to the component that will render it. but it rendered a stringed version of the file.
code is down below (for parent component passing prop down to child ArticleContent component):
const ArticleCnt = () => {
let dispatch = useDispatch()
let {article} = useSelector(s => s.articleContent);
let [file, setFile] = useState(" ");
let location = useLocation();
axios.get("http://localhost:2003/article", {
params: {
id: location.pathname.split("/")[1]
}
})
.then(({data}) => {
dispatch(setArticleContentTo(data))
})
.catch((err) => console.log("Error Occured Here: ", err.message))
.finally(() => {
let doc = article;
setFile(doc)
})
const containerVariants = {
hidden: {
x: "100vw"
},
visible: {
x: 0,
transition: {
duration: .6
}
},
exit: {
x: '-100vw',
transition: {
duration: .6,
delay: 2
}
}
}
return (
<motion.div className="app-main" variants={containerVariants} exit="exit" initial="hidden" animate="visible">
<ArticlePanel />
<div className="app-container">
<ArticleHeader />
<ArticleThumbnail />
<ArticleInfo />
<div className="app-article-cnt">
<ArticleContent articleFile={file} />
<ArticleComment />
</div>
</div>
</motion.div>
);}
code is down below (for child component rendering prop as html content):
const ArticleContent = ({articleFile}) => {
const [isPending, setIsPending] = useState(true);
useEffect(() => {
console.log(articleFile)
if(true){
setIsPending(false);
}else{
setIsPending(true);
}
}, [articleFile]);
return (
<div className="app-article-content">
{
isPending &&
<>
<div>
<h1>
<Skeleton />
</h1>
<Skeleton count={50} />
</div>
</>
}
{
! isPending &&
articleFile
}
</div>
);}