useLoader Hook
The useLoader hook allows you to access the loading state of a specific loader defined in the BetterHtmlProvider context. This is particularly useful for managing loading states in your application.
Usage
To use the useLoader hook, you need to provide the name of the loader as defined in your BetterHtmlProvider's loaders configuration.
import { useLoader, Div } from "react-better-html";
function App() {
const isLoading = useLoader("testLoader");
return <Div.box>{isLoading ? "Loading..." : "Content Loaded"}</Div.box>;
}
In the above example the variable isLoading is boolean and can be used in the component as needed.
Notes
- The
useLoaderhook must be used within a react component. - The
loaderNamemust correspond to a key in theloadersobject provided to theBetterHtmlProvider. - If the
loaderNameis not provided or does not exist, the hook returnsfalse. - This hook is read-only. To control the loading state, use the useLoaderControls hook.