21 lines
628 B
TypeScript
21 lines
628 B
TypeScript
import axios from 'axios'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
// Custom hook to fetch raw file content on mount
|
|
export default function useFileContent(odRawUrl: string): { content: string; error: string; validating: boolean } {
|
|
const [content, setContent] = useState('')
|
|
const [validating, setValidating] = useState(true)
|
|
const [error, setError] = useState('')
|
|
|
|
useEffect(() => {
|
|
axios
|
|
.get(odRawUrl)
|
|
.then(res => setContent(res.data))
|
|
.catch(e => setError(e.message))
|
|
.finally(() => {
|
|
setValidating(false)
|
|
})
|
|
}, [odRawUrl])
|
|
return { content, error, validating }
|
|
}
|