GithubHelp home page GithubHelp logo

Comments (9)

texttechne avatar texttechne commented on May 30, 2024

You don't import it, because it's a babel plugin. Just install it and reference the plugin in your babel configuration (See https://github.com/AlexGilleran/jsx-control-statements#installation). Then you're all set up and you can use it within your JSX.

from jsx-control-statements.

DmitrijOkeanij avatar DmitrijOkeanij commented on May 30, 2024

I use:

"babel": {
    "plugins": [
      "jsx-control-statements"
    ]
  }

in package.json
And after "npm run start" it show
"'If' is not defined react/jsx-no-undef"
Also tried name: "babel-plugin-jsx-control-statements"

from jsx-control-statements.

texttechne avatar texttechne commented on May 30, 2024

You cannot configure babel via package.json. Typically you do the configuration in an own file called .babelrc; of course, there are also different options to configure babel...

Furthermore, if you want to use linting, please read this section: https://github.com/AlexGilleran/jsx-control-statements#linting

from jsx-control-statements.

DmitrijOkeanij avatar DmitrijOkeanij commented on May 30, 2024

Also tried to make .babelrc file in the root folder of the project, and the same result.

{
    "plugins": ["jsx-control-statements"]
}

or

{
    "plugins": ["babel-plugin-jsx-control-statements"]
}

Read here - http://babeljs.io/docs/usage/babelrc about package.json

Working on Windows on VisualStudio Code with default react template.

from jsx-control-statements.

texttechne avatar texttechne commented on May 30, 2024

Ah ok, didn't knew about this package.json option. Thanks.

Anyways, the error is produced by your linter. The concrete rule is: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md

It means that <If> is not defined in your file. And this is of course true, since there is no component with the name If. Jsx-control-statements only transforms component-like structures before react renders them. So to fix this linting issue you need to install an additional plugin: https://github.com/vkbansal/eslint-plugin-jsx-control-statements

Have you configured the jsx-

from jsx-control-statements.

DmitrijOkeanij avatar DmitrijOkeanij commented on May 30, 2024

I have this code in project.json

"babel": {
   "plugins": [
     "jsx-control-statements"
   ]
 },
 "eslintConfig": {
   "plugins": [
     "jsx-control-statements"
   ],
   "parserOptions": {
     "ecmaFeatures": {
         "jsx": true
     }
   },
   "extends": ["plugin:jsx-control-statements/recommended"],
   "rules": {
     "react/jsx-no-undef": [2, { "allowGlobals": true }]
   }
 }

And both modules babel-plugin-jsx-control-statements and eslint-plugin-jsx-control-statements installed. And it shows the same error and result.
Have no idea what i am doing wrong...

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 30, 2024

default react template.

Do you mean you're using Create React App? Unfortunately this doesn't let you override eslint properly so it doesn't work with JSX Control Statements :(

from jsx-control-statements.

DmitrijOkeanij avatar DmitrijOkeanij commented on May 30, 2024

Thank you.
Strange, i don't understand. I thought that this template is like just a directory with subdirectories and files, and if i want I can modify anything in it... I thought that there is an ability to change anything in project and it`s configuration. Maybe something is hardcoded (somewhere) in this template so I can not modify it to make it work?

from jsx-control-statements.

DmitrijOkeanij avatar DmitrijOkeanij commented on May 30, 2024

Oh. Now i understand Create React Template has config files in modules, so if i tried to edit them i broke updating (eject).

from jsx-control-statements.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.