Skip to content

Instantly share code, notes, and snippets.

@jpomykala
Last active January 9, 2017 22:28
Show Gist options
  • Save jpomykala/751cd9ad21122ad696d15a3321cf9445 to your computer and use it in GitHub Desktop.
Save jpomykala/751cd9ad21122ad696d15a3321cf9445 to your computer and use it in GitHub Desktop.
https://www.youtube.com/watch?v=fq02r-M-D8I // Redux Ty stara kurwo zmarnowałaś mi 20 lat życia
class LoginPage extends Component {
test() {
this.props.setLoginState(SignInState.SIGNED_IN)
}
render() {
//... wywołuję test() po naciśnięciu przycisku
}
}
const mapDispatchToProps = (dispatch) => {
return (bindActionCreators({
setLoginState: setLoginState
}, dispatch));
};
export default connect(null, mapDispatchToProps)(LoginPage);
class Navigation extends Component {
render() {
//tutaj chcę odebrać informację
console.debug(this.props.myProp);
//....
}
}
const mapStateToProps = (state) => {
return ({myProp: state.signIn});
};
export default connect(mapStateToProps)(Navigation);
import {LOGIN} from '../actionTypes'
export function setLoginState(signState) {
return {type: LOGIN, signState}
}
export const LOGIN = 'LOGIN'
export const LOGOUT = 'LOGOUT'
import {SignInState} from '../states';
import {LOGIN, LOGOUT} from '../actionTypes';
const initialState = {
signIn: SignInState.SIGNED_OUT
}
export default function login(state = initialState, action) {
switch (action.type) {
case LOGIN:
return {signIn: SignInState.SIGNED_IN};
case LOGOUT:
return {signIn: SignInState.SIGNED_OUT};
default:
return state;
}
}
export const SignInState = {
SIGNED_IN: 'SIGNED_IN',
SIGNED_OUT: 'SIGNED_OUT'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment