Skip to content

Commit

Permalink
useParam()の返り値にnull合体演算子を使用
Browse files Browse the repository at this point in the history
  • Loading branch information
ogu-kazemiya committed Jul 18, 2024
1 parent d20f94c commit 9ea2216
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/lib/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const toStringIfArray = (s: string | undefined | readonly string[]) =>
Array.isArray(s) ? s[0] : s

/**
* @param paramName - 取得するparam、存在しないものを取得しようとした場合、undefinedが返るので注意
* @param paramName - 取得するparam、存在しないものを取得しようとした場合、'undefined'が返るので注意
*/
const useParam = (paramName: string): ComputedRef<string> => {
const route = useRoute()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return computed(() => toStringIfArray(route.params[paramName])!)
return computed(() => toStringIfArray(route.params[paramName]) ?? 'undefined')
}

export default useParam
2 changes: 1 addition & 1 deletion src/pages/ContestPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ onMounted(() => {
</div>
<contest-team-list
:contest-teams="contestDetail.teams"
:contest-id="contestId ?? 'undefined'"
:contest-id="contestId"
/>
</page-container>
</template>
Expand Down

0 comments on commit 9ea2216

Please sign in to comment.