A very tiny SSR-compatible head component for Preact using preact-portal.
It's around 1.5 kB including preact-portal and only ~500 bytes by itself.
Heavily inspired by react-head by tizmagic.
Installation
npm install preact-head-tag
Usage
Client
;; const HelloWorld = <div> <HeadTag tag="title">About this website</HeadTag> <HeadTag tag="meta" name="example" content="whatever" /> <h1>Hello world!</h1> </div>;
// Alternatively you can use the following components for convenience:; const HelloWorld = <div> <Title>About this website</Title> <Meta name="example" content="whatever" /> <h1>Hello world!</h1> </div>;
Server
;;; const headTags = ; // Wrap you App component in the TagCollectorconst app = ; // Put the extracted headTags inside the head of the html.// headTags is an array of strings so use headTags.join("")res;
License
MIT