最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - VScode messes JSX format (beautify) - Stack Overflow

programmeradmin1浏览0评论

I have this plugin installed:

This is code I have

import React, { Component } from 'react';

export default class TempInput extends Component {
  render() {
    return (
      <div>
                <input
          value={temperature}
          onChange={this.handleChange} />


      </div>
    );
  }
}

After clicking Ctrl+Shift+I, first I get message that

Could not determine type to beautify please choose.

Then it allows me to choose from HTML, JS, CSS. When I choose JS, this is result I get:

import React, {
  Component
} from 'react';

export default class TempInput extends Component {
  render() {
    return ( <
      div >
      <
      input value = {
        temperature
      }
      onChange = {
        this.handleChange
      }
      />


      <
      /div>
    );
  }
}

Any idea why? Language mode is set as JS/React in VScode.


If I uninstall that plugin and click Ctrl+Shift+I, I get this error

command 'HookyQR.beautifyFile' not found

I have this plugin installed: https://github.com/HookyQR/VSCodeBeautify

This is code I have

import React, { Component } from 'react';

export default class TempInput extends Component {
  render() {
    return (
      <div>
                <input
          value={temperature}
          onChange={this.handleChange} />


      </div>
    );
  }
}

After clicking Ctrl+Shift+I, first I get message that

Could not determine type to beautify please choose.

Then it allows me to choose from HTML, JS, CSS. When I choose JS, this is result I get:

import React, {
  Component
} from 'react';

export default class TempInput extends Component {
  render() {
    return ( <
      div >
      <
      input value = {
        temperature
      }
      onChange = {
        this.handleChange
      }
      />


      <
      /div>
    );
  }
}

Any idea why? Language mode is set as JS/React in VScode.


If I uninstall that plugin and click Ctrl+Shift+I, I get this error

command 'HookyQR.beautifyFile' not found

Share Improve this question asked May 25, 2018 at 16:49 user9846482user9846482
Add a comment  | 

2 Answers 2

Reset to default 23

You don't need to use plugin for that: Change Language Mode command (Ctrl + KM) offers JavaScript React option, what is basically JS with JSX support.

Native Format Document command (usually bound to Alt + Shift + F) then does the trick.

Use a beautify tool that explicitly supports JSX such as react-beautify or prettier.

VSCodeBeautify may support JSX however seems to be cases where it does not work. See GitHub Issue 132.

发布评论

评论列表(0)

  1. 暂无评论