javascript - sublime 中 react 代码的语法高亮显示

标签 javascript reactjs sublimetext3 syntax-highlighting

我开始用 sublime text 编写一些基本的 React 代码。这是我的语法突出显示的样子。它部分突出显示。有什么建议的 sublime 插件可以用来查看完整的语法高亮显示吗?

enter image description here

import React, { Component } from 'react'
import { connect } from 'react-redux'   // <-- is the glue between react and redux
import { bindActionCreators } from 'redux'
import { selectBook } from '../actions/index'

// there is no intrinsic connection between React and Redux
// they are two seperate libraries
// they are connected using a seperate library called ReactRedux

// container? its a React component that hasa direct connection to state managed by Redux
class BookList extends Component {

    constructor(props) {
        super(props)
        //this.props = props;
    }

    renderList() {
        return this.props.books.map((book) => {
            return (
                <li key={book.title} className="list-group-item">{book.title}</li>
            )
        })
    }

    render() {
        return (
            <ul className="list-group col-sm-4">
                {this.renderList()}
            </ul>
        )
    }

}

// function is the glue between react and redux
function mapStateToProps(state) {
    // Whatever gets retrieved from here will show up as props inside
    // of book-list

    return {
        books: state.books
    }
}

// anything returned from this function will end up as props on the BookList container
function mapDispatchToProps(dispatch) {
    return bindActionCreators({selectBook: selectBook}, dispatch)
}

// Promote BookList from a component to a container - it needs to know
// about this new dispatch method, selectBook. Make it available as a prop
export default connect(mapStateToProps, mapDispatchToProps)(BookList);

编辑:[修复了一些不正确的语法,添加了代码文本]

最佳答案

安装 babel 修复语法高亮。

在sublime3上安装babel的步骤:

  1. 对于 windows:Ctrl+Shift+P 对于 mac: Cmd+Shift+P
  2. 然后键入 安装选择 包控制:安装包
  3. 然后键入 Babel选择 'Babel-Snippets'。稍后它会安装 babel。
  4. 然后在 Sublime3 编辑器中设置 Babel 语法来自:View > Syntax > Babel > Javascript

对于某些用户,Babel 在第 4 步中丢失。他们可以另外安装 Babel,方法是按照相同的步骤并选择 这次 Babel 而不是步骤 3 中的 Babel-Snippets

检查我测试过它:

enter image description here

关于javascript - sublime 中 react 代码的语法高亮显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41319547/

相关文章:

javascript - .getElementById() 最初附加到什么对象?

javascript - angular:调用 el.setAttribute 导致错误

python - 对 Django CORS 问题使用react

ide - 如何更改 Sublime Text 3 中的文件夹和菜单字体大小?

javascript - 将键/值对添加到返回的 Mongoose 对象

javascript - 稍后 Hook ajax成功

go - 覆盖goSublime中的函数签名

c++ - 已解决-Sublime Text for C++中的 “fatal error: opencv: no such file or directory”

javascript - 在子组件 Prop 上使用父 Prop

javascript - react 处理表单提交