To be more precise with the terms used here:
Avoid: all the JSX written here will get compiled
In JSX context, the compiler transpiles JSX syntactic sugar to equivalent JS code.
"...takes the source code of a program written in a programming language as its input and produces an equivalent source code in the same or a different programming language". wiki
While "compiled" usually (always) refers to compilation step.
"...primarily used for programs that translate source code from a high-level programming language to a lower level language". wiki
What really happens here?
Babel used as JSX compiler that transpiles the above JSX:
// Author's claim to avoid
const Component1 = ({ isLoggedIn }) => {
return React.createElement(
React.Fragment,
null,
isLoggedIn &&
React.createElement(
"div",
null,
React.createElement("h1", null, "Example")
),
!isLoggedIn &&
React.createElement(
"div",
null,
React.createElement("h1", null, "Example not logged in"),
React.createElement("div", null, "Some another div"),
React.createElement(SomeComponent, null)
)
);
};
// Author's claim to write
const Component2 = ({ isLoggedIn }) => {
return React.createElement(
React.Fragment,
null,
isLoggedIn && React.createElement(LoggedInComponent, null),
!isLoggedIn && React.createElement(NotLoggedInComponent, null)
);
};
The author nitpicking on redundant memory consumption of the "not used branch" (!isLoggedIn) when transpiling HTML tags instead of converting them to components.
Why component1 is a bad practice and should avoid it?
Its not bad practice (at least where I work), you shouldn't avoid it, keep focusing on readable code.
Author's opinion is on same scale of nintpicking on declaring constant inside render function:
const Component1 = () => {
const x = 5;
return <div>{x}</div>;
};
const x = 5;
const Component2 = () => {
return <div>{x}</div>;
};
There are thousands of similar questions and discussions around the "premature optimization is the root of all evil" topic (lookup for the term).