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

@lexical/react

Package Overview
Dependencies
Maintainers
5
Versions
234
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/react

This package provides Lexical components and hooks for React applications.

  • 0.20.1-nightly.20241129.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
463K
decreased by-7%
Maintainers
5
Weekly downloads
 
Created

What is @lexical/react?

@lexical/react is a powerful and flexible text editor framework for React applications. It provides a set of tools and components to build rich text editors with ease, offering features like collaborative editing, custom formatting, and extensibility.

What are @lexical/react's main functionalities?

Basic Editor Setup

This code sets up a basic Lexical editor with rich text capabilities and history support. The LexicalComposer component initializes the editor with a configuration, and the RichTextPlugin and HistoryPlugin add rich text editing and undo/redo functionality.

import React from 'react';
import { LexicalComposer } from '@lexical/react/LexicalComposer';
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';

const editorConfig = {
  namespace: 'MyEditor',
  theme: {},
  onError: (error) => {
    console.error(error);
  },
};

function MyEditor() {
  return (
    <LexicalComposer initialConfig={editorConfig}>
      <RichTextPlugin
        contentEditable={<ContentEditable />}
        placeholder={<div>Enter some text...</div>}
      />
      <HistoryPlugin />
    </LexicalComposer>
  );
}

export default MyEditor;

Custom Formatting

This code adds a toolbar to the Lexical editor, allowing users to apply custom formatting to their text. The ToolbarPlugin provides a set of formatting options like bold, italic, and underline.

import React from 'react';
import { LexicalComposer } from '@lexical/react/LexicalComposer';
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
import { ToolbarPlugin } from '@lexical/react/LexicalToolbarPlugin';
import { $createTextNode } from 'lexical';

const editorConfig = {
  namespace: 'MyEditor',
  theme: {},
  onError: (error) => {
    console.error(error);
  },
};

function MyEditor() {
  return (
    <LexicalComposer initialConfig={editorConfig}>
      <ToolbarPlugin />
      <RichTextPlugin
        contentEditable={<ContentEditable />}
        placeholder={<div>Enter some text...</div>}
      />
      <HistoryPlugin />
    </LexicalComposer>
  );
}

export default MyEditor;

Collaborative Editing

This code enables collaborative editing in the Lexical editor. The CollaborationPlugin allows multiple users to edit the same document in real-time, identified by a unique room ID.

import React from 'react';
import { LexicalComposer } from '@lexical/react/LexicalComposer';
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
import { CollaborationPlugin } from '@lexical/react/LexicalCollaborationPlugin';

const editorConfig = {
  namespace: 'MyEditor',
  theme: {},
  onError: (error) => {
    console.error(error);
  },
};

function MyEditor() {
  return (
    <LexicalComposer initialConfig={editorConfig}>
      <RichTextPlugin
        contentEditable={<ContentEditable />}
        placeholder={<div>Enter some text...</div>}
      />
      <HistoryPlugin />
      <CollaborationPlugin id="my-collab-room" />
    </LexicalComposer>
  );
}

export default MyEditor;

Other packages similar to @lexical/react

Keywords

FAQs

Package last updated on 29 Nov 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