Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active April 4, 2019 08:58
Show Gist options
  • Select an option

  • Save dewey92/334286f6494b9bab0c1f80bd5c2c8fc6 to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/334286f6494b9bab0c1f80bd5c2c8fc6 to your computer and use it in GitHub Desktop.
JSX Monoid
import React from 'react';
const fragment = children => React.createElement.apply(
null,
[React.Fragment, {}].concat(children)
);
const jsx = createMonoid({
indentity: null,
semigroup: (a, b) => fragment([a, b]),
});
log(jsx.id) // => null
/**
* Will yield:
*
* <React.Fragment>
* <div />
* <span />
* </React.Fragment>
*/
log(jsx.append(<div />, <span />))
/**
* Conceptually, yang akan kita liat pada screen
* hanya <div> kosong. Kita gak akan bisa liat
* tulisan "null" ya kan? 😄
*
* <React.Fragment>
* <div />
* </React.Fragment>
*/
log(jsx.append(<div />, jsx.id))
log(jsx.append(jsx.id, <div />))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment