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

@uiw/react-codemirror

Package Overview
Dependencies
Maintainers
2
Versions
209
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.

  • 4.21.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
674K
increased by6.23%
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 01 Sep 2023

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