Skip to content

Instantly share code, notes, and snippets.

@jack-lewin
Created April 2, 2018 23:05
ReasonML: getting started - actions, reducers, and initialState
type state = {
weather: WeatherData.weather
};
type action =
| WeatherLoaded(WeatherData.weather);
let component = ReasonReact.reducerComponent("App");
let dummyWeather: WeatherData.weather = {
summary: "Warm throughout the day",
temp: 30.5
};
let make = (_children) => {
...component,
initialState: () => {
weather: dummyWeather
},
reducer: (action, _prevState) => {
switch action {
| WeatherLoaded(newWeather) =>
ReasonReact.Update({
weather: newWeather
})
}
},
render: (self) =>
<div className="App">
<p> (ReasonReact.stringToElement(self.state.weather.summary)) </p>
</div>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment