Created
October 25, 2018 03:56
-
-
Save edoantonioco/8cfb52e5cdea5b30f14a8642da4147af to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react'; | |
import { | |
StyleSheet, | |
View, | |
StatusBar, | |
Text, | |
TouchableOpacity, | |
} from 'react-native'; | |
import { Provider, connect } from 'react-redux' | |
//import configureStore from './src/store/configureStore' | |
//import Login from './src/pages/Login'; | |
//import Signup from './src/pages/Signup'; | |
//import Routes from './src/Routes'; | |
import Rutas from './src/Rutas'; | |
//import store from './src/store3/index' | |
import { combineReducers, createStore } from 'redux' | |
import productsReducer from './src/store4/reducers/products-reducers' | |
import userReducer from './src/store4/reducers/user-reducer' | |
import { updateUser } from './src/store4/actions/user-actions' | |
const allReducers = combineReducers({ | |
products: productsReducer, | |
user: userReducer | |
}) | |
const store = createStore( | |
allReducers, | |
{ | |
products: [{ name: 'iPhone' }], | |
user: 'Michael' | |
} | |
); | |
console.log(store.getState()) | |
//const store = configureStore(); | |
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.onUpdateUser = this.onUpdateUser.bind(this) | |
} | |
onUpdateUser() { | |
this.props.onUpdateUser('Sammy') | |
} | |
render() { | |
console.log(this.props) | |
return ( | |
<Provider store={store}> | |
<View style={styles.container}> | |
<StatusBar | |
backgroundColor="#1c313a" | |
barStyle="light-content" | |
/> | |
<TouchableOpacity onPress={this.onUpdateUser}> | |
Update User | |
</TouchableOpacity> | |
<Text>{this.props.user}</Text> | |
<Rutas /> | |
</View> | |
</Provider> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
backgroundColor: '#455a64', | |
flex: 1, | |
// alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
}); | |
const mapStateToProps = state => ({ //receive state from the store | |
products: state.products, | |
user: state.users, | |
}) | |
const mapActionsToProps = { | |
onUpdateUser: updateUser | |
} | |
export default connect(mapStateToProps, mapActionsToProps)(App) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment