Skip to content

Instantly share code, notes, and snippets.

@gvn
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvn/1301ee298f671acc23c1 to your computer and use it in GitHub Desktop.
Save gvn/1301ee298f671acc23c1 to your computer and use it in GitHub Desktop.
React Notes

React Notes

JSX is a JavaScript syntax extension that looks similar to XML. You can use a simple JSX syntactic transform with React.

You don't have to use JSX with React. You can just use plain JS. However, we recommend using JSX because it is a concise and familiar syntax for defining tree structures with attributes.

React can either render HTML tags (strings) or React components (classes).

React's JSX uses the upper vs. lower case convention to distinguish between local component classes and HTML tags.

To use a JavaScript expression as an attribute value, wrap the expression in a pair of curly braces ({}) instead of quotes ("").

// Input (JSX):
var person = <Person name={window.isLoggedIn ? window.name : ''} />;
// Output (JS):
var person = React.createElement(
  Person,
  {name: window.isLoggedIn ? window.name : ''}
);

Data passed from parent to children components is called props, short for properties.

Gotchas

Tooling

Pros/Cons/Considerations

  • Fairly lightweight. ~128KB minified. Bear in mind that this is only the "V" in your MVC.
  • Backed by FB. Very active project development.
  • Starting to be used by other major tech companies, eg Yahoo.
  • Requires transpiling for JSX usage. This may be an issue when linting. Need to look into this more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment