Created
April 2, 2018 23:05
ReasonML: getting started - actions, reducers, and initialState
This file contains 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 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