Is there an agreed-upon convention for indentation in React JSX? 2 spaces, 4 spaces, tabs, etc.
Asked
Active
Viewed 1.9k times
20
-
1Because of the large use of callbacks, many style guides suggest to use `2 spaces` for indentation, but this question regards javascript in general, not react. – Hitmands Apr 28 '16 at 10:01
-
Okay, I agree. Good to know. – Apr 28 '16 at 10:02
-
A bit late to the party. Anyway, I think 2 spaces hides the problem. If you have many callbacks, you should refactor your code instead of adding another layer of indentation. – David Apr 29 '19 at 07:24
4 Answers
22
You should just use the same indentation as the rest of your javascript code.
That said react ecosystem seems to use mostly double spaces so I'd use that for consistency.

silkAdmin
- 4,640
- 10
- 52
- 83
2
You should use the identation style that fit your style. You can use something like ESlint to define a convention. 4 or 2 spaces or tabs, is just a style.

severin.julien
- 1,314
- 15
- 27
0
The react source code and sample code in the React tutorial use 2 spaces. Also it seems like many of the Github projects related to React use 2.

James Lawruk
- 30,112
- 19
- 130
- 137