0.8.7 • Published 7 months ago

@cozyrl/headuard v0.8.7

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Installation

To install Headuard, use npm:

npm install @cozyrl/headuard

Usage

Headuard provides a convenient way to manage essential head elements in your web page. When using Headuard, you can simplify your HTML structure by allowing Headuard to take care of adding necessary head elements for you.

<!doctype html>
<html lang="en">
  
  <head>
    <!-- Leave it to Headuard -->
  </head>
  
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>

</html>
import { useEffect } from "react";
import { Headuard } from "headuard";

const BaseLayout = () => {

    useEffect(() => {

        // Create head elements.
        const titleTag = Headuard.createTitle({ textContent: "My Page Title" });
        const metaTag = Headuard.createMeta({ name: "description", content: "This is a description" });
        const baseTag = Headuard.createBase({ href: "/base", target: "_blank" });
        const scriptTag = Headuard.createScript({ src: "script.js", type: "text/javascript", async: true });
        const linkTag = Headuard.createLink({ rel: "stylesheet", href: "styles.css", type: "text/css" });

        // Mount the head elements.
        const mountedElements = [
            titleTag, 
            metaTag, 
            baseTag, 
            scriptTag, 
            linkTag
        ].map(elem => Headuard.mount(elem));

        return () => {
            // Unmount the head elements when the component is cleaned up
            mountedElements.map(elem => Headuard.unmount(elem));  
        }
    }, [])

    return <>...</>;
};

export default BaseLayout;

API Reference

For detailed information on each method, refer to the API Reference.

Links

Author

  • Salem Djekoun
  • Email: auditif.auvents.0k@icloud.com

License

This project is licensed under the MIT License.

0.8.7

7 months ago

0.8.6

7 months ago

0.8.5

7 months ago

0.8.4

7 months ago

0.8.3

7 months ago

0.8.2

7 months ago

0.8.1

7 months ago

0.8.0

7 months ago