-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4570bf
commit 447be8f
Showing
2 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/basehub/src/react/rich-text/util/extract-text-from-react-node.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Children, isValidElement, ReactNode } from "react"; | ||
|
||
export function extractTextFromChildren(children?: ReactNode) { | ||
let textContent = ""; | ||
|
||
Children.forEach(children, (child) => { | ||
if (typeof child === "string" || typeof child === "number") { | ||
textContent += child; | ||
} else if (isValidElement(child) && child.props.children) { | ||
textContent += extractTextFromChildren(child.props.children); | ||
} | ||
}); | ||
|
||
return textContent; | ||
} |