Giter Club home page Giter Club logo

react-node-to-string's People

Contributors

fritsvancampen avatar josh68 avatar sunknudsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-node-to-string's Issues

Convert to ESM?

Any chance you're thinking about updating this module to use ESM?

I'm running into an issue where react-node-to-string works fine in Vite projects but not in NextJS projects within my component library. It complains because of the default export issue of ESM and CommonJS interop.

non-node children are not rendered as string

if reactNode is a JSX in this structure

<div>
  hello
  {' '}
  <a href="#">test</>
</div>

result would be "test"

expected result would be "hello test"

proposal fix:

"use strict"

import React from "react"

const reactNodeToString = function (reactNode: React.ReactNode): string {
  let string = ""
  if (typeof reactNode === "string") {
    string = reactNode
  } else if (typeof reactNode === "number") {
    string = reactNode.toString()
  } else if (reactNode instanceof Array) {
    reactNode.forEach(function (child) {
      string += reactNodeToString(child)
    })
  } else if (React.isValidElement(reactNode)) {
    string += reactNodeToString(reactNode.props.children)
  }
  return string
}

export default reactNodeToString

placing here as I can't do a pull request :)

Pure Iterable type not handled

According to react type declaration:

type ReactFragment = Iterable<ReactNode>;
type ReactNode = ReactElement | string | number | ReactFragment | ReactPortal | boolean | null | undefined;

The ReactFragment is an Iterable<ReactNode> not an Array, which is not instanceof Array and may not contain forEach method

Sourcemaps from npm reference source files not included in the package

build/index.js has //# sourceMappingURL=index.js.map
build/index.js.map has "sources":["../src/index.ts"]
but src/index.ts is not included, causing:

WARNING in ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-node-to-string/build/index.js
Module Warning (from ../../node_modules/.pnpm/[email protected][email protected]/node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '<workspace>/node_modules/.pnpm/[email protected][email protected]/node_modules/react-node-to-string/src/index.ts' file: Error: ENOENT: no such file or directory, open '<workspace>/node_modules/.pnpm/[email protected][email protected]/node_modules/react-node-to-string/src/index.ts'

tree node_modules/.pnpm/[email protected][email protected]/
node_modules/.pnpm/[email protected][email protected]/
└── node_modules
    ├── react -> ../../[email protected]/node_modules/react
    └── react-node-to-string
        ├── build
        │   ├── index.d.ts
        │   ├── index.js
        │   └── index.js.map
        ├── LICENCE
        ├── package.json
        └── README.md

4 directories, 6 files

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.