Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react'
- import PropTypes from 'prop-types'
- import {connect} from 'react-redux'
- import {login, logout} from '../actions/index'
- const SimpleA0 = ({loggedIn, onClick}) => {
- return (
- <div>
- <h4>Simple Admin component</h4>
- {
- loggedIn ?
- <p>Hey, you are logged in</p> :
- <p>You are not logged in</p>
- }
- <button onClick={() => onClick(loggedIn)}>{
- loggedIn? 'Logout': 'Login'
- }</button>
- </div>
- )
- }
- SimpleA0.propTypes = {
- loggedIn: PropTypes.bool.isRequired,
- onClick: PropTypes.func.isRequired
- }
- const SimpleA = connect(
- state => ({
- loggedIn: state.user.loggedIn
- }),
- dispatch => {
- return ({
- onClick: loggedIn => {
- console.log(loggedIn)
- dispatch(loggedIn? logout.request(): login.request())
- }
- })
- }
- )(SimpleA0)
- export default SimpleA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement