Skip to content

Instantly share code, notes, and snippets.

@rapPayne
Last active September 14, 2023 17:51
Show Gist options
  • Save rapPayne/fb5daa144472735abe61517b366bd0b7 to your computer and use it in GitHub Desktop.
Save rapPayne/fb5daa144472735abe61517b366bd0b7 to your computer and use it in GitHub Desktop.
React component styled with inline styles
// 💩
// Much more complex; see all the "style={styles.whatever}"? They get in the way
// of quickly understanding what's in this component.
export const ChangeName = ({ user, update, save }) => {
return (
<section style={styles.wrapper}>
<div style={styles.formGroup}>
<label htmlFor="user" style={styles.label}>User name</label>
<input id="user" onChange={e => update(e.target.value)} value={user} />
</div>
<button style={styles.button} onClick={save}>Save</button>
</section>
)
}
// And the rules of CSS largely don't apply any more. It's no longer possible
// to apply styles based on position, or relation, or to use pseudo-classes.
// Yuck!
const styles = {
wrapper: {
border: "1px solid var(--dark1)",
padding: "10px",
},
formGroup: {
margin: "10px",
},
label: {
display: "block",
},
input: {
fontSize: "1.5em",
display: "block",
},
button: {
color: "var(--light1)",
backgroundColor: "var(--dark1)",
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment