Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React JSX style guide

What is the standard style for jsx? Specifically when HTML is intertwined with js. Are the parenthesis after return in the correct spot? Anyone know of any good formatters that don't mess everything up?

render: function(){
    return (
      <li>
        <input id={this.props.id} type="checkbox" />
        <label htmlFor={this.props.id}>{this.props.tag}</label>
      </li>
    );
  }
like image 514
user3552325 Avatar asked Feb 26 '16 22:02

user3552325


People also ask

What is Airbnb style guide?

The Airbnb style guide is a set of best practices and guidelines for generating quality code. It is one of the most popular style guides available on Github.

What is JSX format?

JSX stands for JavaScript XML. It is simply a syntax extension of JavaScript. It allows us to directly write HTML in React (within JavaScript code). It is easy to create a template using JSX in React, but it is not a simple template language instead it comes with the full power of JavaScript.

Does Airbnb use React JS?

However, Uber Eats isn't the only app well known for using React Native. The second platform that React has allowed to spread its wings is Airbnb.


2 Answers

I like to use Airbnb code style with Web Storm Editor provide good support for jsx syntax.

Note: you can apply Airbnb style automatically inside Web Storm from Settings->Code Quality


render() {
  return (
    <MyComponent className="long body" foo="bar">
      <MyChild />
    </MyComponent>
  );
}
like image 115
Nour Sammour Avatar answered Oct 17 '22 21:10

Nour Sammour


Found a good style guide here https://github.com/airbnb/javascript/blob/master/react/README.md

like image 21
user3552325 Avatar answered Oct 17 '22 21:10

user3552325