overleaf/services/web/frontend/js/features/file-tree/contexts/file-tree-create-form.tsx
Alf Eaton 0cde5be165 Merge pull request #14709 from overleaf/ae-context-typescript
Convert React context providers to TypeScript [don't squash!]

GitOrigin-RevId: d92a91798286978410956ab791d73c17c5086d86
2024-01-29 09:03:04 +00:00

30 lines
766 B
TypeScript

import { createContext, FC, useContext, useState } from 'react'
const FileTreeCreateFormContext = createContext<
{ valid: boolean; setValid: (value: boolean) => void } | undefined
>(undefined)
export const useFileTreeCreateForm = () => {
const context = useContext(FileTreeCreateFormContext)
if (!context) {
throw new Error(
'useFileTreeCreateForm is only available inside FileTreeCreateFormProvider'
)
}
return context
}
const FileTreeCreateFormProvider: FC = ({ children }) => {
// is the form valid
const [valid, setValid] = useState(false)
return (
<FileTreeCreateFormContext.Provider value={{ valid, setValid }}>
{children}
</FileTreeCreateFormContext.Provider>
)
}
export default FileTreeCreateFormProvider