2024-01-26 09:23:48 +00:00
|
|
|
import { createContext, FC, useContext, useState } from 'react'
|
2021-03-18 09:52:36 +00:00
|
|
|
|
2024-01-26 09:23:48 +00:00
|
|
|
const FileTreeCreateFormContext = createContext<
|
|
|
|
{ valid: boolean; setValid: (value: boolean) => void } | undefined
|
|
|
|
>(undefined)
|
2021-03-18 09:52:36 +00:00
|
|
|
|
|
|
|
export const useFileTreeCreateForm = () => {
|
|
|
|
const context = useContext(FileTreeCreateFormContext)
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error(
|
|
|
|
'useFileTreeCreateForm is only available inside FileTreeCreateFormProvider'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:23:48 +00:00
|
|
|
const FileTreeCreateFormProvider: FC = ({ children }) => {
|
2021-03-18 09:52:36 +00:00
|
|
|
// is the form valid
|
|
|
|
const [valid, setValid] = useState(false)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeCreateFormContext.Provider value={{ valid, setValid }}>
|
|
|
|
{children}
|
|
|
|
</FileTreeCreateFormContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-01-26 09:23:48 +00:00
|
|
|
export default FileTreeCreateFormProvider
|