1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Inline Style Attributes Should Be Camel Cased as a react til

This commit is contained in:
jbranchaud
2017-10-11 07:27:53 -05:00
parent ef52a99eae
commit b9809a329a
2 changed files with 25 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
For a steady stream of TILs from a variety of rocketeers, checkout
[til.hashrocket.com](https://til.hashrocket.com/).
_574 TILs and counting..._
_575 TILs and counting..._
---
@@ -407,6 +407,7 @@ _574 TILs and counting..._
### React
- [Force A Component To Only Have One Child](react/force-a-component-to-only-have-one-child.md)
- [Inline Style Attributes Should Be Camel Cased](react/inline-style-attributes-should-be-camel-cased.md)
- [Passing Props Down To React-Router Route](react/passing-props-down-to-react-router-route.md)
### Ruby

View File

@@ -0,0 +1,23 @@
# Inline Style Attributes Should Be Camel Cased
When adding a few quick styles to React components, you can add it directly
on the tags in the JSX. To do this, use the `style` tag with a plain old
JavaScript object of styles.
```javascript
<div style={{ padding: "1em", color: "#fff" }}>
```
If you are using a CSS attribute that is normally hyphenated like
`padding-top` or `background-color`, you'll need to camel case it in the
JSX.
```javascript
<div style={{ paddingTop: "1em", backgroundColor: "#fff" }}>
```
This is because our styles now need to conform to JavaScript syntax
rules since they are in the form of a POJO.
Read the [documentation](https://reactjs.org/docs/dom-elements.html#style)
for more details.