2.0.3 • Published 7 years ago

react-document-title v2.0.3

Weekly downloads
75,160
License
MIT
Repository
github
Last release
7 years ago

React Document Title

Provides a declarative way to specify document.title in a single-page app.
This component can be used on server side as well.

Built with React Side Effect.

====================

Installation

npm install --save react-document-title

Dependencies: React >= 0.13.0

Features

  • Does not emit DOM, not even a <noscript>;
  • Like a normal React compoment, can use its parent's props and state;
  • Can be defined in many places throughout the application;
  • Supports arbitrary levels of nesting, so you can define app-wide and page-specific titles;
  • Works just as well with isomorphic apps.

Example

Assuming you use something like react-router:

var App = React.createClass({
  render: function () {
    // Use "My Web App" if no child overrides this
    return (
      <DocumentTitle title='My Web App'>
        <this.props.activeRouteHandler />
      </DocumentTitle>
    );
  }
});

var HomePage = React.createClass({
  render: function () {
    // Use "Home" while this component is mounted
    return (
      <DocumentTitle title='Home'>
        <h1>Home, sweet home.</h1>
      </DocumentTitle>
    );
  }
});

var NewArticlePage = React.createClass({
  mixins: [LinkStateMixin],

  render: function () {
    // Update using value from state while this component is mounted
    return (
      <DocumentTitle title={this.state.title || 'Untitled'}>
        <div>
          <h1>New Article</h1>
          <input valueLink={this.linkState('title')} />
        </div>
      </DocumentTitle>
    );
  }
});

Server Usage

If you use it on server, call DocumentTitle.rewind() after rendering components to string to retrieve the title given to the innermost DocumentTitle. You can then embed this title into HTML page template.

Because this component keeps track of mounted instances, you have to make sure to call rewind on server, or you'll get a memory leak.

But What About Meta Tags?

Looking for something more powerful? Check out React Helmet!

@gooddata/goodstrapd5-layoutglobalization-idmp-nodejs-application@productfy/commonflowbuilder-testlipemat-js-boilerplateant-design-pro-scaffoldant-design-pro-cs@ltaoo/bisheng-theme-antd@rem-js/rem-ant-design-pro@yuanhong/artipub@crawlab-team/artipub-frontendelon-npmlink-testcommon-xubt-member-sitetestba1ltestbalyml-public-uimingdao-web-mohodatahzero-boothzero-boot-purehzero-front-runtimefn-fpp-uikitsimple-antd-management-fast-frameworkzcx-uimedipass-overlordstatics-theme-bloggersnapgitcognitiveleap-corecognitiveleap-core-usskill-f3gratico-ui@infinitebrahmanuniverse/nolb-react-domingdao-web-mo@everything-registry/sub-chunk-2551snbc-paas-bootcpaas-bootcura-uidfxk-admin-toolscook-clidory@catalog/coredemy-commondashboard-app-inboxdashboard-nextprivate_mng_compsperidotpivot2picidar-theme-crystalpicidae-theme-crystalpicidae-theme-grasspicidae-theme-haierplate-modeldoloribusquasdocumittu-template-defaultdocom-theme-antddocz-theme-antddocument-title-adpter1qiaozuiqiezizhibo-basketball-management-platformqiezizhibo-management-platformqgopolymath-uipolymath-ui-stagingchastlove@dingyun/platform-typesci-competition-modulerosid-handler-componentsrondsframeworkempty-single-page-scaffoldenms-modulerhino-design-app@evkj/x-site-admin-client@hicooper/doc-editorcli-service-deps@dkpkg/dk-lib-reactjs@doreamonjs/gatefed-react-componentfastmodel-layout-componentsfareeda-component-library@indoqa/react-starter@icedesign/ice-website-homepage@icedesign/iceworks-homepage-scaffold@icedesign/scafford-pro@icedesign/scalable-aside-layout@icedesign/website-homepage-scaffold@icedesign/scaffold-analytical@icedesign/scaffold-cms@icedesign/post-platfrom-scaffold@icedesign/scaffold-ice-website-homepage@icedesign/scaffold-pro@icedesign/landing-layout@icedesign/aside-layout@icedesign/basic-layout@icedesign/header-aside-footer-layout@icedesign/header-aside-footer-responsive-layout@icedesign/header-footer-layout@icedesign/demo-layout@icedesign/fixed-header-footer-responsive-layout@icedesign/creator-admin-scaffold
2.0.3

7 years ago

2.0.2

8 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

10 years ago

0.1.0

10 years ago