Socket
Socket
Sign inDemoInstall

@uiw/react-codemirror

Package Overview
Dependencies
Maintainers
2
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uiw/react-codemirror

CodeMirror component for React.


Version published
Weekly downloads
583K
increased by2.38%
Maintainers
2
Weekly downloads
 
Created

What is @uiw/react-codemirror?

@uiw/react-codemirror is a React component for CodeMirror, a versatile text editor implemented in JavaScript for the browser. It provides a flexible and customizable code editor with support for various programming languages, themes, and extensions.

What are @uiw/react-codemirror's main functionalities?

Basic Usage

This code demonstrates the basic usage of @uiw/react-codemirror. It imports the necessary modules and sets up a simple CodeMirror editor with JavaScript syntax highlighting.

import React from 'react';
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';

const App = () => {
  return (
    <CodeMirror
      value="console.log('Hello, world!');"
      height="200px"
      extensions={[javascript()]}
    />
  );
};

export default App;

Theming

This example shows how to apply a theme to the CodeMirror editor. The 'oneDark' theme is imported and added to the extensions array.

import React from 'react';
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { oneDark } from '@codemirror/theme-one-dark';

const App = () => {
  return (
    <CodeMirror
      value="console.log('Hello, world!');"
      height="200px"
      extensions={[javascript(), oneDark]}
    />
  );
};

export default App;

Handling Events

This code demonstrates how to handle change events in the CodeMirror editor. The 'handleChange' function logs the new value to the console whenever the content changes.

import React from 'react';
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';

const App = () => {
  const handleChange = (value, viewUpdate) => {
    console.log('Value changed:', value);
  };

  return (
    <CodeMirror
      value="console.log('Hello, world!');"
      height="200px"
      extensions={[javascript()]}
      onChange={handleChange}
    />
  );
};

export default App;

Other packages similar to @uiw/react-codemirror

Keywords

FAQs

Package last updated on 05 Sep 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