Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Fix tab default
  • Loading branch information
BrunoQuaresma committed Nov 16, 2022
commit aedeec711a806ec309798bf5e91e66c4518a3772
6 changes: 3 additions & 3 deletions site/src/hooks/useTab.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useSearchParams } from "react-router-dom"

export interface UseTabResult {
value: string | null
value: string
set: (value: string) => void
}

export const useTab = (tabKey: string): UseTabResult => {
export const useTab = (tabKey: string, defaultValue: string): UseTabResult => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we assign a default value here in case the consumer doesn't pass one in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know what value it can be so I think we can left it required for now.

const [searchParams, setSearchParams] = useSearchParams()
const value = searchParams.get(tabKey)
const value = searchParams.get(tabKey) ?? defaultValue

return {
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const TemplateVersionPage: FC = () => {
const [state] = useMachine(templateVersionMachine, {
context: { versionName, orgId },
})
const tab = useTab("file")
const tab = useTab("file", "0")
const { t } = useTranslation("templateVersionPage")

return (
Expand Down