Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

preact-render-to-string

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preact-render-to-string

Render JSX to an HTML string, with support for Preact components.

  • 3.8.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
decreased by-4.07%
Maintainers
1
Weekly downloads
 
Created

What is preact-render-to-string?

The preact-render-to-string package is used to render Preact components to HTML strings, which can be used for server-side rendering (SSR), generating static pages, or even testing components by comparing the output string. It is specifically designed for use with the Preact library, which is a fast 3kB alternative to React with the same modern API.

What are preact-render-to-string's main functionalities?

Render Preact components to HTML

This feature allows you to render a Preact component to an HTML string. It is useful for server-side rendering to send the initial HTML to the browser.

import { h } from 'preact';
import renderToString from 'preact-render-to-string';

const MyComponent = () => <div>Hello, World!</div>;
const html = renderToString(<MyComponent />);
console.log(html); // Outputs: <div>Hello, World!</div>

Render with JSX

You can use JSX syntax to define the components that you want to render to a string, making it easy to write and understand.

import { h } from 'preact';
import renderToString from 'preact-render-to-string';

const html = renderToString(<div className='example'>Example</div>);
console.log(html); // Outputs: <div class="example">Example</div>

Render with options

The package allows you to pass options to the render function, such as 'pretty' for pretty-printed HTML output.

import { h } from 'preact';
import renderToString from 'preact-render-to-string';

const MyComponent = () => <div>Hello, World!</div>;
const html = renderToString(<MyComponent />, { pretty: true });
console.log(html); // Outputs HTML with nice formatting

Other packages similar to preact-render-to-string

Keywords

FAQs

Package last updated on 17 Aug 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc