mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
0cde5be165
Convert React context providers to TypeScript [don't squash!] GitOrigin-RevId: d92a91798286978410956ab791d73c17c5086d86
30 lines
766 B
TypeScript
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
|