Skip to content

Instantly share code, notes, and snippets.

@alainlompo
Created August 18, 2017 10:54
Show Gist options
  • Save alainlompo/04afe047651ddab9b3c93b04a25cca99 to your computer and use it in GitHub Desktop.
Save alainlompo/04afe047651ddab9b3c93b04a25cca99 to your computer and use it in GitHub Desktop.
Simple jsx sample snippets to familiarize the beginner with its key concepts and syntax (Episode 1 of probably many...)
function formatName(user) {
return user.firstName + ' ' + user.lastName;
}
const user = {
firstName:'Harper',
lastName:'Perez'
};
const element = (
<h1>
hello, {formatName(user)}!
</h1>
);
ReactDOM.render(element,
document.getElementById('root')
);
function getGreeting(user) {
if (user) {
return <h1>Hello, {formatName(user)}!</h1>
}
return <h1>Hello, Stranger </h1>;
}
const element2 = <div tableIndex="0"></div>
const element3 = <img src={user.avatarUrl} />
const element4 = (
<div>
<h1>Hello!</h1>
<h2> Good to see you here.</h2>
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment