Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const store = createStore(loginReducer);
- export function logout() { return {type: 'USER_LOGIN'} }
- export function logout() { return {type: 'USER_LOGOUT'} }
- export function loginReducer(state={isLogged:false}, action) {
- switch(action.type) {
- case 'USER_LOGIN':
- return {isLogged:true};
- case 'USER_LOGOUT':
- return {isLogged:false};
- default:
- return state;
- }
- }
- class App extends Component {
- lout(){
- console.log(store.getState()); //IT SHOW INITIAL STATE
- store.dispatch(login());
- console.log(store.getState()); //IT SHOWS THAT STATE DID CHANGE
- }
- ////THIS IS THE PROBLEM,
- render() {
- return (
- <Provider store={store}>
- {store.getState().isLogged ?
- <MainComponent store={store} /> :
- <View style={style.container}><Text onPress={this.lout}>Please login</Text></View>}
- </Provider>
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement