The excellent CodeMirror editor as a React.js component.
Live demo: JedWatson.github.io/react-codemirror
To build the examples locally, run:
npm install npm start Then open localhost:8000 in a browser.
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 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')); valueStringthe editor valueoptionsObject (newValue)options passed to the CodeMirror instanceonChangeFunction (newValue)called when a change is madeonFocusChangeFunction (focused)called when the editor is focused or loses focus
See the CodeMirror API Docs for the available options.
MIT. Copyright (c) 2015 Jed Watson.