HtmlRenderer

Custom HTML display

A flexible React component that dynamically renders HTML elements based on a provided configuration array.

VersionLicenseDownloadsBundle Size (minified)Bundle Size (minified + gzip)

Overview

This documentation provides instructions on how to use the HtmlRenderer component in your React projects. The HtmlRenderer component is part of the abaabil.htmlrenderer library.

import HtmlRenderer from 'abaabil.htmlrenderer';

Key Features

Discover why Abaabil's HtmlRenderer component stands out:

  • Dynamic rendering of HTML elements
  • Flexible configuration through a simple array structure
  • Support for custom CSS classes
  • Efficient rendering with React's key prop

Basic Usage

The HtmlRenderer component can be easily integrated into your React applications. Provide a configuration array to render dynamic HTML elements.

Properties

The HtmlRenderer component accepts the following property:

block

Type: Array<{ id: string, Tag: string, text: string, className?: string }>

Description: An array of objects defining the HTML elements to be rendered.

Configuration Object Structure

Each object in the block array should have the following structure:

id

Type: string

Description: A unique identifier for the element (used as the React key).

Tag

Type: string

Description: The HTML tag name to be rendered (e.g., 'div', 'p', 'h1').

text

Type: string

Description: The text content to be rendered inside the element.

className

Type: string

Description: Optional CSS classes to be applied to the element.

Best Practices

Follow these best practices when using the HtmlRenderer component:

  • Ensure unique 'id' values for each element in the block array
  • Use semantic HTML tags when appropriate
  • Leverage the className property for consistent styling
  • Consider memoizing the block array if it's derived from complex calculations

Use Cases

The HtmlRenderer component is particularly useful in scenarios such as:

  • Rendering dynamic content from an API or CMS
  • Creating flexible layout systems
  • Implementing user-configurable UI elements
  • Generating HTML from structured data

Performance Considerations

The HtmlRenderer component is designed with performance in mind:

  • Efficient rendering using React's key prop
  • Minimal overhead with a simple mapping function
  • No unnecessary re-renders when used with memoized props

Limitations

Be aware of the following limitations when using the HtmlRenderer:

  • Does not support nested elements or complex HTML structures
  • Limited to text content only (no support for child components)
  • No built-in sanitization for user-generated content