Created
August 23, 2017 08:34
-
-
Save fstiffo/f2cb0b5785a7c0d01b85ac55edec89d5 to your computer and use it in GitHub Desktop.
Reason React first component try
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
| let component = ReasonReact.statefulComponent "CommentConfirmation"; | |
| type state = {showConfirm: bool}; | |
| let make ::onConfirm children => { | |
| let toggleConfirmMessage _event {ReasonReact.state: state} => | |
| ReasonReact.Update {showConfirm: not state.showConfirm}; | |
| let confirmAction _event _self => { | |
| onConfirm; | |
| ReasonReact.Update {showConfirm: false} | |
| }; | |
| { | |
| ...component, | |
| initialState: fun () => {showConfirm: false}, | |
| render: fun {state, update} => { | |
| let confirmNode = | |
| state.showConfirm ? | |
| <span> | |
| <a href="" onClick=(update confirmAction)> (ReasonReact.stringToElement "Yes") </a> | |
| <span> (ReasonReact.stringToElement "- or -") </span> | |
| <a href="" onClick=(update toggleConfirmMessage)> | |
| (ReasonReact.stringToElement "No") | |
| </a> | |
| </span> : | |
| <a href="" onClick=(update toggleConfirmMessage)> children </a>; | |
| <div className="comment-confirm"> confirmNode </div> | |
| } | |
| }; | |
| () | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment