var myOtherName = "Cavill"; // normal JS
var myName = <p>henry {name2}</p>; //JSX (write html inside brackets, and also inject JS back in between html)<h1 class="btn">hey</h1> NO <h1 className="btn">hey</h1> YES<img /> and not <img>)var fancyFunction(){
console.log("something something millenium hand and shrimp")
};
const kitty = (<img onClick={fancyFunction} src="#" alt="kitty" />)&& operators, used often in React. ternary operators also used often in React. called short circuit operators { condition && <p>show-this-jsx-thing</p>}
false && (anything) is short-circuit evaluated to false. true || (anything) is short-circuit evaluated to true.const strings = ['Home', 'Shop', 'About Me'];
const listItems = strings.map(string => <li>{string}</li>);
const jsx_var = <ul>{listItems}</ul>
// the above will return an array! because map returns an array.
will return
key as in <li key="li-01">Example</li>, sorta like id="" in htmlNot all lists need to have keys. A list needs keys if either of the following are true:const people = ["Rowe", "Prevost", "Gare"];
const peopleLis = people.map((person, i) => (
// expression goes here:
<li key={"person_" + i}>{person}</li>
));React uses JSX (javascript precompiler) which looks like html
<p class"thingy" style="thingy-black">thing</p> will work<p>JSX here</p><h1 class="btn"></h1> -> <h1 className="btn"></h1><img> and <input> MUST BE <img /> and <input />var name = 'hey' can be used in JSX as var jsx = (<h1>{name}</h1>h1>);Cool stuff : attribute assignment
const pics = {
panda: "http://bit.ly/1Tqltv5",
owl: "http://bit.ly/1XGtkM3",
owlCat: "http://bit.ly/1Upbczi",
};
const panda = <img src={pics.panda} alt="Lazy Panda" />;
const owl = <img src={pics.owl} alt="Unimpressed Owl" />;
const owlCat = <img src={pics.owlCat} alt="Ghastly Abomination" />;<img onClick={myFunction} />