How to use react-from-dom - 2 common examples

To help you get started, we’ve selected a few react-from-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gilbarbara / react-inlinesvg / src / index.tsx View on Github external
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));
    }
  }
github gilbarbara / react-inlinesvg / src / index.tsx View on Github external
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;

react-from-dom

Convert HTML/XML source code or DOM nodes to React elements

MIT
Latest version published 8 months ago

Package Health Score

61 / 100
Full package analysis

Popular react-from-dom functions