Skip to content

Instantly share code, notes, and snippets.

@alexpilugin
Last active March 13, 2017 23:50
Show Gist options
  • Save alexpilugin/a57967ff23d8369a9840f3d4f48f663e to your computer and use it in GitHub Desktop.
Save alexpilugin/a57967ff23d8369a9840f3d4f48f663e to your computer and use it in GitHub Desktop.
React tips and hints

Functional stateless (dumb) React component

function Hello(props) {
  return <div>Hello {props.name} </div>;
}

ES6+

const Hello = props => <div>Hello {props.name}</div>;

or ES6+ destructuring on props:

const Hello = ({name}) => (<div>Hello {name}</div>);

Another example:

function ClicableDiv(props) {
  return (
    <div onClick={props.onClick}>
      {props.children}
    </div>
  );
}

The same example with ES6+ destructoring on props:

const ClicableDiv = ({onClick, children}) => (
  <div onClick={onClick}>
    {children}
  </div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment