Skip to content

Commit 817732c

Browse files
committed
onlyText導入
1 parent fb1f241 commit 817732c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/components/Term/index.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Tippy from "@tippyjs/react";
44
import { MdArrowForward } from "react-icons/md";
55
import "tippy.js/dist/tippy.css";
66
import "tippy.js/themes/material.css";
7+
import { onlyText } from "react-children-utilities";
78
import styles from "./styles.module.css";
89
import definitions from "./definitions";
910
import shortDefinitions from "./short-definitions.js";
@@ -15,14 +16,10 @@ import typeMap from "./type-map.js";
1516
* @param {React.ReactNode} props.children
1617
*/
1718
export default function Term({ type = null, children }) {
18-
function unwrapNode(node) {
19-
if (typeof node === "string") return node;
20-
else return unwrapNode(node.props.children);
21-
}
22-
if (type === null) type = typeMap.get(unwrapNode(children));
19+
if (type === null) type = typeMap.get(onlyText(children));
2320
if (!type)
2421
throw new Error(
25-
`Problem: Term ${children.textContent} is not defined in type-map.js .
22+
`Problem: Term ${onlyText(children)} is not defined in type-map.js .
2623
Solution: explicitly specify term type, or add type definition to type-map.js`,
2724
);
2825

0 commit comments

Comments
 (0)