Socket
Socket
Sign inDemoInstall

preact-render-to-string

Package Overview
Dependencies
Maintainers
8
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.


Version published
Weekly downloads
1.4M
decreased by-0.75%
Maintainers
8
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 29 Aug 2024

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