Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getElement() {
try {
const node = this.getNode() as Node;
const element = convert(node);
if (!element || !React.isValidElement(element)) {
throw new InlineSVGError('Could not convert the src to a React element');
}
this.setState({
element,
status: STATUS.READY,
});
} catch (error) {
this.handleError(new InlineSVGError(error.message));
}
}
private getNode() {
const { description, title } = this.props;
try {
const svgText = this.processSVG();
const node = convert(svgText, { nodeOnly: true });
if (!node || !(node instanceof SVGSVGElement)) {
throw new InlineSVGError('Could not convert the src to a DOM Node');
}
const svg = this.updateSVGAttributes(node);
if (description) {
const originalDesc = svg.querySelector('desc');
if (originalDesc && originalDesc.parentNode) {
originalDesc.parentNode.removeChild(originalDesc);
}
const descElement = document.createElement('desc');
descElement.innerHTML = description;