Skip to content

leetcode/react-codemirror

Repository files navigation

Codemirror

The excellent CodeMirror editor as a React.js component.

Demo & Examples

Live demo: JedWatson.github.io/react-codemirror

To build the examples locally, run:

npm install npm start 

Then open localhost:8000 in a browser.

Installation

The easiest way to use codemirror is to install it from NPM and include it in your own React build process (using Browserify, Webpack, etc).

You can also use the standalone build by including dist/codemirror.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.

npm install react-codemirror --save 

Usage

var React = require('react'), Codemirror = require('react-codemirror'); var App = React.createClass({getInitialState: function(){return{code: "// Code" }}, updateCode: function(newCode){this.setState({code: newCode })}, render: function(){var options ={lineNumbers: true }; return <Codemirror value={this.state.code} onChange={this.updateCode} options={options} />} }); React.render(<App />, document.getElementById('app')); 

Properties

  • valueString the editor value
  • optionsObject (newValue) options passed to the CodeMirror instance
  • onChangeFunction (newValue) called when a change is made
  • onFocusChangeFunction (focused) called when the editor is focused or loses focus

See the CodeMirror API Docs for the available options.

License

MIT. Copyright (c) 2015 Jed Watson.

About

Codemirror Component for React.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript88.1%
  • CSS6.9%
  • HTML5.0%