Skip to content

Commit

Permalink
fix: don't crash when interacting with empty link field
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusforsberg committed May 6, 2024
1 parent da03787 commit 35ff362
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/CustomLinkInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ export function CustomLinkInput(
const linkValue = useFormValue(props.path.slice(0, -1)) as LinkValue | null
const [options, setOptions] = useState<CustomLinkTypeOptions[] | null>(null)

const customLinkType = props.customLinkTypes.find((type) => type.value === linkValue!.type)!
const customLinkType = props.customLinkTypes.find((type) => type.value === linkValue!.type)

useEffect(() => {
if (Array.isArray(customLinkType.options)) {
setOptions(customLinkType.options)
} else {
customLinkType
.options(document, props.path, workspace.currentUser)
.then((options) => setOptions(options))
if (customLinkType) {
if (Array.isArray(customLinkType?.options)) {
setOptions(customLinkType.options)
} else {
customLinkType
.options(document, props.path, workspace.currentUser)
.then((options) => setOptions(options))
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customLinkType.options, props.path, workspace.currentUser])
}, [customLinkType, props.path, workspace.currentUser])

return options ? (
<Select
Expand Down

0 comments on commit 35ff362

Please sign in to comment.