-
-
Save idkjs/a5faa6384c8438c18493f9fb1982ca1e to your computer and use it in GitHub Desktop.
A simple SignupForm written in ReasonML
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
| type action = | |
| | UpdateEmail string | |
| | UpdatePassword string; | |
| type state = { | |
| email: string, | |
| password: string | |
| }; | |
| let component = ReasonReact.reducerComponent "Signup"; | |
| let handleSubmit _ (self: ReasonReact.self _ _ _) => Js.log self.state; | |
| let getEventTargetValue event :string => ( | |
| ReactDOMRe.domElementToObj ( | |
| ReactEventRe.Form.target event | |
| ) | |
| )##value; | |
| let make _children => { | |
| ...component, | |
| initialState: fun () => {email: "", password: ""}, | |
| reducer: fun action state => | |
| switch action { | |
| | UpdateEmail value => ReasonReact.Update {...state, email: value} | |
| | UpdatePassword value => ReasonReact.Update {...state, password: value} | |
| }, | |
| render: fun self => | |
| <div className="Login"> | |
| <div> <h2> (ReasonReact.stringToElement "Signup here") </h2> </div> | |
| <form onSubmit=(self.handle handleSubmit)> | |
| <input | |
| onChange=(self.ReasonReact.reduce (fun event => UpdateEmail (getEventTargetValue event))) | |
| placeholder="email" | |
| /> | |
| <input | |
| onChange=(self.reduce (fun event => UpdatePassword (getEventTargetValue event))) | |
| placeholder="password" | |
| /> | |
| <input _type="submit" value="Register" /> | |
| </form> | |
| </div> | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment