Giter Club home page Giter Club logo

Comments (6)

remarkablemark avatar remarkablemark commented on September 27, 2024 1

For the 1st error, can you return void since the return type should either be a React element or void (returning the domNode shouldn't really do anything):

-        return domNode // error 1
+        return

For the 2nd error, can you use type assertion:

-        return <>{domToReact(domNode.children, options)}</> // error 2
+        return <>{domToReact((domNode as Element).children as DOMNode[], options)}</>

Preferably you should check domNode instanceof Element instead of domNode as Element to prevent runtime errors.

You can import Element and DOMNode from:

import { Element, DOMNode } from 'html-react-parser';

from html-react-parser.

harryzcy avatar harryzcy commented on September 27, 2024 1

Thanks, the method works.

from html-react-parser.

remarkablemark avatar remarkablemark commented on September 27, 2024 1

I decided to add back the object return type for replace option in order to fix error 1. See #1129

from html-react-parser.

remarkablemark avatar remarkablemark commented on September 27, 2024

Release:

from html-react-parser.

Bkumar48 avatar Bkumar48 commented on September 27, 2024

` const options: HTMLReactParserOptions = {
replace: (domNode: DOMNode) => {
if (!(domNode instanceof Element)) return;
if (domNode.name === "ul") {
return (


    {domToReact(domNode.children as DOMNode[])}

);
}

  if (domNode.name === "li") {
    return (
      <li className="flex gap-2 items-center ">
        <Icons.PinkArrowMarker />
        {domToReact(domNode.children as DOMNode[])}
      </li>
    );
  }
},

};`
Only first condition is getting replaced, can anyone help me with this?

from html-react-parser.

remarkablemark avatar remarkablemark commented on September 27, 2024

@Bkumar48 can you open a new issue and provide a reproducible example?

from html-react-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.