I currently have a Python bs4 script which loads a .svg file and lets me change some text, colors and a few other things in it.
Today I decided to start working on a SaaS version of this script. I decided that I will probably use Python/Django for the back end in case I need some work done on the svg in the back end via bs4, and React for the front end, since it's really the only front end technology I am familiar with.
But I am having issues with loading, editing and showing the .svg files in React. I used axios
for loading the .svg(it's currently locally hosted but in the future it's going to be on AWS or something) and jssoup
npm package for finding elements in my svg.
Here's my current code:
import React, { useEffect, useState } from "react";
import axios from "axios";
import JSSoup from "jssoup";
function App() {
const [pic, setPic] = useState("");
useEffect(() => {
axios
.get("./newfile.svg")
.then((res) => {
var soup = new JSSoup(res.data, false);
let elements = soup.findAll("g");
console.log(elements);
setPic(soup.prettify());
})
.catch((err) => console.log("Error, ", err));
}, []);
return (
<div className="App">
<img src={`data:image/svg+xml;utf8,${pic}`} />
</div>
);
}
export default App;
First question is, am I even using the correct tool for the job? Is JavaScript even capable of such work? Next question is, how am I supposed to actually show the .svg after doing some work on it with jssoup?