Using React within an Atom Package


Is it possible to run React within an Atom package?

I keep getting a React error indicating that the Atom views are not DOM elements.

Invariant Violation: _registerComponent(...): Target container is not a DOM element.

In this case I’m simply running a basic React demo within the generated file

React = require 'react'

module.exports =
class ReactTestView
  constructor: ->
    @element = document.createElement('div')
    @element.setAttribute 'id', 'react-render'

    Component = React.createClass
      displayName: 'Component'

      render: ->
        React.DOM.div("Hello #{}!")

    component = React.createFactory(Component)
    React.render(component(name: "World"), document.getElementById 'react-render')

I understand React is no longer used in Atom, but I would like to create a plugin of significant complexity.

If it can’t work, alternatively, does anyone know of an example using a variant of Flux with Space-Pen? Possibly utilizing atoms event emitters.


Does anyone know of a working example using ‘react-for-atom’?


Others will be able to give more precise instructions here, but have you thought of checking the shadow DOM for your element instead?


I think that may be part of the issue. Targeting inside of shadow DOM may explain the underlying error message:

Invariant Violation: _registerComponent(...): Target container is not a DOM element.

However, I’m unable to even get a ‘hello world’ working when targeting the document.body.


A working solution: atom-react-starter, and demo example: atom-ftp-editor.


The approach you took in atom-react-starter is the pattern Nuclide has adopted as well. The main.js file is responsible for creating the mounting node for the root React component.

const FooComponent = ...;
const React = ...;

let panel;
let root;

module.exports = {
  activate() {
    root = document.createElement('div');
      <FooComponent />,
    panel = atom.workspace.addBottomPanel({item: root});
  deactivate() {


I’ve developer a larger working app, the code is available online: site, github