February 2019
Beginner to intermediate
180 pages
4h 4m
English
This reducer component renders a form where every customer field is editable inside an input element. The component has two modes—Create and Update—based on the window.location.pathname.
We start by binding to window.location.pathname, and defining our component's actions and state:
/* Customer.re */[@bs.val] external pathname: string = "window.location.pathname";type mode = | Create | Update;type state = { mode, customer: CustomerType.t,};type action = | Save(ReactEvent.Form.t);let component = ReasonReact.reducerComponent("Customer");
Next, we add our component styles using bs-css. To see the styles, check out Chapter07/app-end/src/customers/Customer.re:
/* Customer.re */module Styles = { open Css; let form = style([ ... ]); ...Read now
Unlock full access