Skip to content

Commit 8d1799b

Browse files
author
woi
committed
update ExampleScreen with new API
1 parent 9aa96a5 commit 8d1799b

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

App/Containers/Example/ExampleScreen.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Style from './ExampleScreenStyle'
99
/**
1010
* This is an example of a container component.
1111
*
12-
* This screen displays a little help message and shows the weather temperature.
12+
* This screen displays a little help message and informations about a fake user.
1313
* Feel free to remove it.
1414
*/
1515

@@ -20,43 +20,48 @@ const instructions = Platform.select({
2020

2121
class ExampleScreen extends React.Component {
2222
componentDidMount() {
23-
this.props.fetchTemperature()
23+
this.props.fetchUser()
2424
}
2525

2626
render() {
27-
let temperature = this.props.temperatureIsLoading ? '...' : this.props.temperature
28-
if (temperature === null) {
29-
temperature = '??'
27+
let user = this.props.userIsLoading ? '...' : this.props.user
28+
if (user === null) {
29+
user = '??'
3030
}
3131

3232
return (
3333
<View style={Style.container}>
3434
<Text style={Style.title}>TheCodingMachine boilerplate</Text>
3535
<Text style={Style.text}>To get started, edit App.js</Text>
3636
<Text style={Style.text}>{instructions}</Text>
37-
<Text style={Style.text}>The weather temperature is: {temperature}</Text>
38-
<Text style={Style.text}>{this.props.isHot ? "It's pretty hot!" : ''}</Text>
39-
<Text style={Style.text}>{this.props.temperatureErrorMessage}</Text>
40-
<Button onPress={this.props.fetchTemperature} title="Refresh" />
37+
<Text style={Style.text}>
38+
{user === '...'
39+
? 'Data are loading...'
40+
: this.props.userErrorMessage
41+
? this.props.userErrorMessage
42+
: ''}
43+
</Text>
44+
<Text style={Style.text}>{user ? "I'm a fake user, my name is " + user.name : ''}.</Text>
45+
<Button onPress={this.props.fetchUser} title="Refresh" />
4146
</View>
4247
)
4348
}
4449
}
4550

4651
ExampleScreen.propsTypes = {
47-
temperature: PropTypes.number,
48-
temperatureErrorMessage: PropTypes.string,
52+
user: PropTypes.number,
53+
userIsLoading: PropTypes.bool,
54+
userErrorMessage: PropTypes.string,
4955
}
5056

5157
const mapStateToProps = (state) => ({
52-
temperature: state.example.get('temperature'),
53-
temperatureErrorMessage: state.example.get('temperatureErrorMessage'),
54-
temperatureIsLoading: state.example.get('temperatureIsLoading'),
55-
isHot: isHot(state),
58+
user: state.example.get('user').toJS(),
59+
userIsLoading: state.example.get('userIsLoading'),
60+
userErrorMessage: state.example.get('userErrorMessage'),
5661
})
5762

5863
const mapDispatchToProps = (dispatch) => ({
59-
fetchTemperature: () => dispatch(ExampleActions.fetchTemperature()),
64+
fetchUser: () => dispatch(ExampleActions.fetchUser()),
6065
})
6166

6267
export default connect(

0 commit comments

Comments
 (0)