{"library":"react-node-to-string","title":"React Node to String Extractor","description":"react-node-to-string is a minimalist utility package designed to extract the plain text content from a React node (`React.ReactNode`) object. It recursively traverses the children of a React node, concatenating all string literals it encounters while ignoring JSX elements and their structural information. The current stable version is 0.1.2, indicating a pre-1.0.0 status, which typically means a stable but possibly feature-complete and low-maintenance lifecycle given its focused scope. It offers a simpler, more lightweight alternative to methods like `ReactDOMServer.renderToStaticMarkup` when only the string content is required, avoiding the overhead of full HTML rendering. Its primary use case is for scenarios where one needs to obtain the textual representation of a React component's children without any HTML tags or complex component logic, making it suitable for content-extraction or display purposes.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install react-node-to-string"],"cli":null},"imports":["import reactNodeToString from 'react-node-to-string';","import { type ReactNode } from 'react';\nimport reactNodeToString from 'react-node-to-string';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { ReactNode } from \"react\";\nimport reactNodeToString from \"react-node-to-string\";\n\ninterface MyComponentProps {\n  children?: ReactNode;\n}\n\n// Example usage with a simple React node\nconst simpleNode: ReactNode = (\n  <p>\n    Hello, <strong>world</strong>! This is a <span>test</span>.\n  </p>\n);\n\nconsole.log(\"Simple Node String:\", reactNodeToString(simpleNode));\n// Expected output: Hello, world! This is a test.\n\n// Example with a functional component children\nconst MyComponent = ({ children }: MyComponentProps) => (\n  <div>\n    Extracted: {reactNodeToString(children)}\n  </div>\n);\n\n// Imagine rendering MyComponent somewhere\nconst componentNode: ReactNode = (\n  <MyComponent>\n    <span>Nested text</span> and more <em>content</em>.\n  </MyComponent>\n);\n\n// To demonstrate the extraction, we pass the children directly.\n// In a real app, you'd render MyComponent and then process its output if needed.\nconst contentToExtract = (\n  <><span>Nested text</span> and more <em>content</em>.</>\n);\n\nconsole.log(\"Component Children String:\", reactNodeToString(contentToExtract));\n// Expected output: Nested text and more content.","lang":"typescript","description":"Demonstrates importing and using `reactNodeToString` to extract text from various ReactNode structures, including JSX elements and nested components.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}