This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/contrib/!frameworks/react
2015-08-24 21:32:52 -04:00
..
img React (JSX and ES6 ready) contribution layer 2015-08-24 21:32:52 -04:00
packages.el Fix tern integration (see #2400) 2015-08-24 21:32:52 -04:00
README.org React (JSX and ES6 ready) contribution layer 2015-08-24 21:32:52 -04:00

React contribution layer for Spacemacs

/TakeV/spacemacs/media/commit/4938a535e4dc671e53506f845c35458530938fd2/contrib/!frameworks/react/img/react.png

logo

Description

ES6 and JSX ready configuration layer for React It will automatically recognize .jsx and .react.js files

Features

  • on-the-fly syntax checking
  • proper syntax highlight and indentation with jsx
  • ternjs turbocharged autocompletion as in js2-mode

TODO Install

To use this contribution add it to your ~/.spacemacs

  (setq-default dotspacemacs-configuration-layers '(react))

You will also need to install tern to use the auto-completion and documentation features:

  $ npm install -g tern

To use the on-the-fly syntax checking, install eslint with babel and react support:

  $ npm install -g eslint babel-eslint eslint-plugin-react

If your project do not use a custom .eslintrc file I strongly advice you to try out this one by Airbnb: .eslintrc

Optional Configuration

You may refer to the web-mode configuration for fine tuning the indenting behaviour.

For example to have a consistent 2 spaces indenting both on js and jsx you may use these settings:

  (setq-default
   ;; js2-mode
   js2-basic-offset 2
   ;; web-mode
   css-indent-offset 2
   web-mode-markup-indent-offset 2
   web-mode-css-indent-offset 2
   web-mode-code-indent-offset 2
   web-mode-attr-indent-offset 2)

And if you want to have 2 space indent also for element's attributes, concatenations and contiguous function calls:

  (with-eval-after-load 'web-mode
    (add-to-list 'web-mode-indentation-params '("lineup-args" . nil))
    (add-to-list 'web-mode-indentation-params '("lineup-concats" . nil))
    (add-to-list 'web-mode-indentation-params '("lineup-calls" . nil)))