Skip to content

Instantly share code, notes, and snippets.

@alizhdanov
Last active November 14, 2017 11:18
Show Gist options
  • Save alizhdanov/4f385ceb71ff2a4b6cb63af5a8f17b76 to your computer and use it in GitHub Desktop.
Save alizhdanov/4f385ceb71ff2a4b6cb63af5a8f17b76 to your computer and use it in GitHub Desktop.
React docs cheat sheat

Handling Events

  • React events are named using camelCase, rather than lowercase.
  • With JSX you pass a function as the event handler, rather than a string.
<button onClick={activateLasers}>
  Activate Lasers
</button>

You cannot return false to prevent default behavior in React. You must call preventDefault explicitly.

function ActionLink() {
  function handleClick(e) {
    e.preventDefault();
    console.log('The link was clicked.');
  }

  return (
    <a href="#" onClick={handleClick}>
      Click me
    </a>
  );
}

State and Lifecycle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment