New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-document

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-document

Customizable default Document component

latest
Source
npmnpm
Version
0.7.1
Version published
Maintainers
1
Created
Source

React Document

This component provides a React Component to render a HTML Document with common functionality. It can be integrated into webpack static builds as well as SSR.

React Document aims to provide a static interface for other libraries to generate dom.

Install

npm install --save react-document

Props

<Document />

Props

- htmlProps?: { [key: string]: string }

Optional. React props for the html element.

- bodyProps?: { [key: string]: string }

Optional. React props for the body element.

- app?: string

Optional. A string to dangerously set inside the app mount element. Usually a rendered React app.

- appMountId?: string

Optional. The id of the app mount element. Defaults to 'app'.

- title?: string

Optional. Title of the document, rendered in a <title> tag.

- viewport?: string

Optional. Configuration for the viewport meta tag. Defaults to a mobile friendly width=device-width, initial-scale=1.

- head?: ReactElement[]

Optional. Array of React elements to render inside the <head> tag.

Optional. Array of React elements to render in the footer, after the content of the page.

- js?: string[]

Optional. Array of urls to load with script tags. These are placed in the <head> with the defer attribute. This allows the browser to start preloading the script but delay execution until the DOM is ready.

- css?: string[]

Optional. Array of urls to load with stylesheet link tags in the head.

- window?: { [key: string]: any }

Optional. Object who's own properties are safely serialized to JSON and attached to the browser's window object in corresponding keys.

Extending Document

Inspired by Next.js, it's easy to customize the Document without breaking other integrations:

import Document, { Html, Head, Body, App, Footer } from 'react-document'

export class MyDocument extends Document {
  render() {
    return (
      <Html>
        <Head>
          {/* Roboto */}
          <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
        </Head>
        <Body>
          <App />
          <Footer />
          {/* Pixel */} 
          <img height="1" width="1" style={{display: 'none'}}
            src="https://www.facebook.com/tr?id=...&amp;ev=PageView&amp;noscript=1"
          />
        </Body>
      </Html>
    )
  }
}

Usage in SSR

import Document from 'react-document'
import { renderToStaticMarkup, renderToString } from 'react/server'

// ... in rendering context:
const app = renderToString(<App />)
const document = '<!doctype html>' + renderToStaticMarkup(
  <Document
    title="Hello World"
    app={app}
    appMountId="root"
  />
)

Usage with webpack-dev-server

Check out jsx-document-webpack-plugin.

FAQs

Package last updated on 03 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts