Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra spaces in JSX #5

Open
oliverjam opened this issue Sep 18, 2020 · 1 comment
Open

Extra spaces in JSX #5

oliverjam opened this issue Sep 18, 2020 · 1 comment

Comments

@oliverjam
Copy link

Week10TT/src/App.js

Lines 38 to 41 in 91f8cac

<div className="Container">
{" "}
<SnakeGrid face={userData.avatar_url} />
</div>

You can probably delete any random extra spaces like this (the {" "}).

This is a weird thing that happens with Prettier that I thought I'd clarify. JSX differs slightly from HTML in how it handles whitespace. HTML is totally whitespace-sensitive (as in spaces in your code between inline elements will cause an actual space to appear on the page). JSX is whitespace-sensitive between elements but not at the end of a line.

When this combines with Prettier aggressively putting things on new lines when the line gets too long you have a problem. E.g. if you have

<span>Some stuff</span> <button>Other</button>

(with a space in the middle) if Prettier moved the button onto a new line that could potentially change your page layout (since the space would disappear). To ensure it doesn't break anything Prettier preserves the space by making it a JS string, using curly brackets and quotes. This forces React to keep it there.

tl;dr you can probs delete these unless you're using spaces to layout your HTML elements 🙃

@trishtracking
Copy link
Contributor

thanks! yeh I couldn't figure that out this morning 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants