1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-reasonml/components/Counter.re
Nicholas Rakoto 016920e3e0 Example: Improve ReasonML example (#3021)
* Git ignore with-reasonml/lib folder

The lib folder contains code generated by BuckleScript, it shouldn't be
versioned.

* Fix, case sensitive paths

Next.js use case-sensitive-paths-webpack-plugin and BuckleScript tries
to maintain the filename case.

* Refactor, use a .babelrc file instead of a babel config in package.json

This is the official recommended way in Next.js

* Enable way, way, waaaay nicer error messages!

Adds `"bsc-flags": ["-bs-super-errors"]` to the bsconfig.json file.

https://reasonml.github.io/community/blog/#way-way-waaaay-nicer-error-messages

* Fix npm scripts & use concurrently to run bsb & next in parallel for dev

* Upgrade bs-platform

* Replace statefulComponent with new reducerComponent

https://github.com/reasonml/reason-react/blob/master/HISTORY.md#024

* Upgrade with-reasonml example to next.js 3
2017-09-30 22:02:45 +02:00

22 lines
521 B
ReasonML

type action =
| Add;
let component = ReasonReact.reducerComponent "Counter";
let make _children => {
...component,
initialState: fun () => 0,
reducer: fun action state =>
switch action {
| Add => ReasonReact.Update {state + 1}
},
render: fun self => {
let countMsg = "Count: " ^ (string_of_int self.state);
<div>
<p> (ReasonReact.stringToElement countMsg) </p>
<button onClick=(self.reduce (fun _event => Add))> (ReasonReact.stringToElement "Add") </button>
</div>
}
};