From 967363e48a7c7ce7bf458c218e7b829a028686fc Mon Sep 17 00:00:00 2001 From: Sakura Knoll Date: Tue, 11 Jul 2023 02:58:24 +0900 Subject: [PATCH] Add null guards --- src/components/v2-pre/FormattedText.tsx | 3 +++ src/lib/v2-pre/data/formatText.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/v2-pre/FormattedText.tsx b/src/components/v2-pre/FormattedText.tsx index 4dc962af..a14587c9 100644 --- a/src/components/v2-pre/FormattedText.tsx +++ b/src/components/v2-pre/FormattedText.tsx @@ -6,6 +6,9 @@ interface FormattedTextProps { } const FormattedText = ({ children }: FormattedTextProps) => { + if (children == null) { + children = '' + } const tokens = tokenize(children) return <>{renderTokens(tokens)} diff --git a/src/lib/v2-pre/data/formatText.ts b/src/lib/v2-pre/data/formatText.ts index 4a73780e..69075b9c 100644 --- a/src/lib/v2-pre/data/formatText.ts +++ b/src/lib/v2-pre/data/formatText.ts @@ -64,7 +64,10 @@ export function formatSubSkillInfo({ ) } -export function replaceNewLine(value: string = '') { +export function replaceNewLine(value: string) { + if (value == null) { + value = '' + } return value.replace(/\\n/g, '\n') }