React intellisense in Visual Studio Code

后端 未结 5 2162
忘了有多久
忘了有多久 2021-01-31 18:39

I\'m sure I\'m missing something simple, but I simply can\'t get React.js IntelliSense to work in Visual Studio code.

I have done the following:

  • npm
5条回答
  •  你的背包
    2021-01-31 19:19

    Finally got this working, with go to definition and all working with react jsx. You need jsconfig.json, looking like this (note you need the "jsx": "react" property, and to specify the trailing 'index.jsx' in the aliases, if using the implicit class-as-folder-name paradigm):

    { 
        "compilerOptions": {
            "baseUrl": "./src",
            "paths": { 
                "shared/*":       ["./components/shared/*/index.jsx"],
                "components/*":   ["./components/*/index.jsx"],
                "stores/*":       ["./lib/stores/*"],
                "services/*":     ["./lib/services/*"],
                "utils/*":        ["./lib/utils/*"]
            },
            "module": "commonjs",
            "target": "es6",
            "moduleResolution": "classic",
            "jsx": "react"
        }
    }
    

    Then imports like this all work:

    import UserApi from 'services/api/UserApi';
    import EditArea from 'components/views/Blog/EditArea';
    import EditableLabel from 'shared/EditableLabel';
    

    Hope it helps!

提交回复
热议问题