Skip to content

Instantly share code, notes, and snippets.

@datvtwkm
Last active August 26, 2018 07:41
Show Gist options
  • Save datvtwkm/7213dd33f18d53ec1f9ddee803aed3d4 to your computer and use it in GitHub Desktop.
Save datvtwkm/7213dd33f18d53ec1f9ddee803aed3d4 to your computer and use it in GitHub Desktop.
// @flow
import React, {Component} from 'react';
import type {ComponentType} from 'react';
import {connect} from 'redux';
import {
View,
Button,
Text
} from 'react-native';
import {START_FETCH_SOME_THING} from '../redux/actionTypes';
import {setContainer} from '../utils/global-container'
type Props = {
startFetch: ()=> void
}
type State = {
loading: boolean,
result: string,
error: string
}
function mapDispatchToProps(dispatch) {
return({
startFetch () => {dispatch(START_FETCH_SOME_THING)}
})
}
@connect(null, mapDispatchToProps)
export default class CallingContainer extended Component<Props, State> {
state={
loading: false,
result: '',
error: ''
}
name="callingContainer"
press = () => {
setContainer(this);
this.props.startFetch();
}
render(){
const {loading, result ,error} = this.state;
return(
<View>
{loading ? <Text>Loading</Text> : null}
{result === 'success' ? <Text>Success</Text> : null}
{result === 'failure' ? <Text>Error: {error}</Text> : null}
<Button title="fetch" onPress={this.press}/>
</View>
)}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment