sajad torkamani
import ReactDOMServer from 'react-dom/server'

// Get text content of React element
export function getNodeText(
  node: React.ReactElement | string | number,
): string {
  const nodeHtml = ReactDOMServer.renderToString(node)

  const wrapperElement = document.createElement('div')
  wrapperElement.innerHTML = nodeHtml

  return wrapperElement.textContent || ''
}
Tagged: React

Leave a comment

Your email address will not be published. Required fields are marked *