Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@shopify/react-html
Advanced tools
@shopify/react-html
A component to render your react app with no static HTML.
$ yarn add @shopify/react-html
The <HTML>
component serves as a top level wrapper for a react application, allowing you to avoid needing any kind of server side template, in favour of purely using reactDom.renderToString
.
import * as React from 'react';
import { renderToString } from 'react-dom/server';
import HTML, {DOCTYPE} from '@shopify/react-html';
import MyApp from '../app';
export default (ctx, next) => {
// we have to prepend DOCTYPE to serve valid HTML
ctx.body = DOCTYPE + renderToString(
<HTML>
<MyApp />
</HTML>
);
await next();
}
Due to limitations in react's implementation of HTML, you still need to prepend the <!DOCTYPE html>
directive. To assist with this the module also exports a DOCTYPE
constant.
The component will automatically propagate any usage of the react-helmet
module in your app's content to manipulate the title or other top level HTML or HEAD attributes.
export interface Props {
children?: React.ReactNode;
styles?: Asset[];
scripts?: Asset[];
blockingScripts?: Asset[];
headData?: {[id: string]: any};
data?: {[id: string]: any};
hideForInitialLoad?: boolean;
}
interface Asset {
path: string;
integrity?: string;
}
interface Browser {
userAgent: string;
supported: boolean;
}
Most simple applications will only need these basic properties.
children
The children to be rendered inside the #app
div.
styles Descriptors for any style tags you want to include in the HEAD of the document.
scripts
Descriptors for any script tags you want to include in your document. All scripts passed to this property will be deferred by appending them to the end of the document. We encourage this as a default, although you may use blockingScripts
for any scripts that must be included in the HEAD of the document.
blockingScripts Descriptors for any script tags you want to include in the HEAD of the document. These will block HTML parsing until they are evaluated, so use them carefully.
hideForInitialLoad Sets the body contents to be hidden for the initial render. Use this when injecting stylesheets dynamically in development in order to prevent a flash of unstyled content.
These props are useful for more complex applications that want to synchronize redux, apollo, translation, or any other data across the network boundary. These props are stringified into the DOM using (@shopify/react-serialize
)[https://github.com/Shopify/quilt/blob/master/packages/react-serialize/README.md].
headData
Any serializable data that needs to be available from the DOM when the synchronousScripts
are run.
data
Any serializable data that needs to be available from the DOM when the deferredScripts
are run.
This module also exports the asset components the <HTML />
component uses internally for it's script and style props.
import {Style, Script} from '@shopify/react-html';
The <Style />
component lets you render <link>
tags in your document dynamically as part of your react app.
<Style
href="./some-style.css"
integrity="some-integrity-hash"
crossOrigin="anonymous"
/>
The <Script />
component lets you render <script>
tags in your document dynamically as part of your react app.
<Script
src="./some-script.js"
integrity="some-integrity-hash"
crossOrigin="anonymous"
/>
FAQs
A component to render your React app with no static HTML
The npm package @shopify/react-html receives a total of 13,600 weekly downloads. As such, @shopify/react-html popularity was classified as popular.
We found that @shopify/react-html demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.