Function: js-jsx-mode

js-jsx-mode is an autoloaded, interactive and byte-compiled function defined in js.el.gz.

Signature

(js-jsx-mode)

Documentation

Major mode for editing JavaScript+JSX.

Simply makes js-jsx-syntax buffer-local and sets it to t.

js-mode may detect and enable support for JSX automatically if it appears to be used in a JavaScript file. You could also customize js-jsx-regexps to improve that detection; or, you could set js-jsx-syntax to t in your init file, or in a
.dir-locals.el file, or using file variables; or, you could call
js-jsx-enable in js-mode-hook. You may be better served by one of the aforementioned options instead of using this mode.

In addition to any hooks its parent mode might have run, this mode runs the hook js-jsx-mode-hook, as the final or penultimate step during initialization.

Probably introduced at or before Emacs version 25.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/js.el.gz
;; Since we made JSX support available and automatically-enabled in
;; the base `js-mode' (for ease of use), now `js-jsx-mode' simply
;; serves as one other interface to unconditionally enable JSX in
;; buffers, mostly for backwards-compatibility.
;;
;; Since it is probably more common for packages to integrate with
;; `js-mode' than with `js-jsx-mode', it is therefore probably
;; slightly better for users to use one of the many other methods for
;; enabling JSX syntax.  But using `js-jsx-mode' can’t be that bad
;; either, so we won’t bother users with an obsoletion warning.

;;;###autoload
(define-derived-mode js-jsx-mode js-mode "JavaScript"
  "Major mode for editing JavaScript+JSX.

Simply makes `js-jsx-syntax' buffer-local and sets it to t.

`js-mode' may detect and enable support for JSX automatically if
it appears to be used in a JavaScript file.  You could also
customize `js-jsx-regexps' to improve that detection; or, you
could set `js-jsx-syntax' to t in your init file, or in a
.dir-locals.el file, or using file variables; or, you could call
`js-jsx-enable' in `js-mode-hook'.  You may be better served by
one of the aforementioned options instead of using this mode."
  :group 'js
  (js-jsx-enable)
  (setq-local comment-region-function #'js-jsx--comment-region)
  (js-use-syntactic-mode-name))