Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active June 18, 2021 19:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/550f08a1b635bb9b430ac6be61a9606e to your computer and use it in GitHub Desktop.
Save nathansmith/550f08a1b635bb9b430ac6be61a9606e to your computer and use it in GitHub Desktop.
React 101™

React 101™

All these examples do essentially the same thing.

return (
  <MyComponent
    something={something}
    somethingElse={somethingElse}
  >
    Child text
  </MyComponent>
);
const children = 'Child text';

return (
  <MyComponent
    something={something}
    somethingElse={somethingElse}
  >
    {children}
  </MyComponent>
);
return (
  <MyComponent
    children='Child text'
    something={something}
    somethingElse={somethingElse}
  />
);
const children = 'Child text';

const props = {
  children,
  something,
  somethingElse
};

return (
  <MyComponent
    {...props}
  />
);
const children = ['Child text'];

const props = {
  something,
  somethingElse
};

return React.createElement(
  MyComponent,
  props,
  children
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment