Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't add a 'px' string suffix to numeric values in a JSX inline style object
React interprets a plain number for most CSS length properties in an inline `style` object as pixels already — `{ height: 300 }` is equivalent to `{ height: '300px' }`, so the string and its quotes are unnecessary.
Bad example
| 1 | <div style={{ height: '300px', width: '100px' }} /> |
Explanation (EN)
The string and unit are redundant — React already appends `px` to bare numbers for length-valued style properties.
Objašnjenje (HR)
String i jedinica su suvišni — React već dodaje `px` na gole brojeve za CSS svojstva koja predstavljaju duljinu.
Good example
| 1 | <div style={{ height: 300, width: 100 }} /> |
Explanation (EN)
A plain number is shorter and renders identically for pixel-based style properties.
Objašnjenje (HR)
Obični broj je kraći i renderira se identično za CSS svojstva bazirana na pikselima.