Last active
April 4, 2019 08:58
-
-
Save dewey92/334286f6494b9bab0c1f80bd5c2c8fc6 to your computer and use it in GitHub Desktop.
JSX Monoid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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