Coder Social home page Coder Social logo

uiwjs / react-head Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 16.95 MB

React components will manage your changes to the document head

Home Page: https://uiwjs.github.io/react-head

License: MIT License

Shell 0.78% TypeScript 86.46% HTML 12.75%
head react-component react-head reactjs react jsx

react-head's Introduction

react-head

Buy me a coffee CI npm version NPM Downloads Coverage Status

React components will manage your changes to the document head, like react-helmet

Quick Start

npm install @uiw/react-head

Using

import React, { useState } from "react";
import Head from '@uiw/react-head';

export default function App() {
  const [count, setCount] = useState(1);
  const click = () => setCount(count + 1)
  return (
    <div className="container">
      <Head>
        <Head.Meta charSet="utf-8" />
        <Head.Title>{count} React Head</Head.Title>
        <Head.Link rel="canonical" href="https://uiwjs.github.io" />
      </Head>
      <button onClick={click}>
        Switch Title - "{count}"
      </button>
    </div>
  );
}

Style

import React, { useState } from "react";
import Head from '@uiw/react-head';

const css = `.box-test { color: red; }`

export default function App() {
  return (
    <div>
      <Head.Style>{css}</Head.Style>
      <Head>
        <Head.Style>{css}</Head.Style>
      </Head>
      <div className="box-test">Text Color</div>
    </div>
  );
}

outputs:

<head>
  <style>.box-test { color: red; }</style>
  <style>.box-test { color: red; }</style>
</head>
<!-- .... -->

Meta

import React, { useState } from "react";
import Head from '@uiw/react-head';

export default function App() {
  const [count, setCount] = useState(1);
  const click = () => setCount(count + 1)
  return (
    <div>
      <Head.Meta name="keywords" content="react-head,uiw,uiwjs" />
      <Head.Meta charSet="utf-8" />
      <Head.Meta name="description" content={`${count} React components will manage your changes to the document head.`} />
      <button onClick={click}>
        Modify Meta name=description - "{count}"
      </button>
    </div>
  );
}

Outputs:

<head>
  <meta name="keywords" content="react-head,uiw,uiwjs">
  <meta name="description" content="1 React components will manage your changes to the document head.">
</head>

Modify Favicon

<Head.Link rel="icon" href="/favicon.ico" />
<Head.Link rel="icon" type="image/svg+xml" href="/favicon.svg" />
import React, { useState } from "react";
import Head from '@uiw/react-head';

const favicon = `data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>๐Ÿฆ–</text></svg>`
const favicon2 = `data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>๐Ÿคก</text></svg>`

export default function App() {
  const [show, setShow] = useState(false);
  return (
    <div>
      <Head.Link rel="icon" type="image/svg+xml" href={show ? favicon : favicon2} />
      <button onClick={() => setShow(!show)}>
        Change Favicon {show ? "๐Ÿฆ–" : "๐Ÿคก"} {String(show)}
      </button>
    </div>
  );
}

Outputs:

<head>
  <link data-head="true" rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>๐Ÿคก</text></svg>" />
</head>

All Sub Components

Elements that can be used inside the <head>:

Development

  1. Dependencies in the installation package and example
npm install
  1. To develop, run the self-reloading build:
npm run build  # Compile packages      ๐Ÿ“ฆ @uiw/react-head
npm run watch  # Real-time compilation ๐Ÿ“ฆ @uiw/react-head
  1. Run Document Website Environment:
npm run start
  1. To contribute, please fork repos, add your patch and tests for it (in the test/ folder) and submit a pull request.
npm run test

Contributors

As always, thanks to our amazing contributors!

Made with contributors.

License

Licensed under the MIT License.

react-head's People

Contributors

jaywcjlove avatar pinkchampagne17 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

react-head's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
  • peaceiris/actions-gh-pages v3
  • ncipollo/release-action v1
npm
core/package.json
  • @babel/runtime ^7.18.9
  • @types/react ^18.0.17
  • @types/react-dom ^18.0.6
  • react ^18.2.0
  • react-dom ^18.2.0
  • react >=16.9.0
  • react-dom >=16.9.0
package.json
  • @kkt/less-modules ^7.5.4
  • @kkt/ncc ^1.1.1
  • compile-less-cli ^1.8.13
  • husky ^8.0.1
  • lerna ^8.0.0
  • lint-staged ^15.0.0
  • prettier ^3.0.1
  • tsbb ^4.1.14
  • node >=16.0.0
website/package.json
  • @uiw/react-markdown-preview-example ^2.0.0
  • react ^18.2.0
  • react-dom ^18.2.0
  • @types/react ^18.0.17
  • @types/react-dom ^18.0.6
  • kkt ^7.5.4
  • markdown-react-code-preview-loader ^2.1.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.