Created
August 16, 2019 15:47
-
-
Save thevishnupradeep/757eebe092544769328e6dc7f3bc4a56 to your computer and use it in GitHub Desktop.
This file contains 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
/*********************** Imports ***********************/ | |
import React from 'react'; | |
import { connect } from 'react-redux'; | |
import { useDispatch } from 'react-redux'; | |
/********************* End Imports *********************/ | |
/*********************** Toggle Function ***********************/ | |
const Toggle = (props) => { | |
const isOpen = useSelector(state => state.isOpen); | |
const dispatch = useDispatch(); | |
const toggleOpenState = () => { | |
dispatch({ type: "TOGGLE_STATE" }); | |
} | |
return ( | |
<div> | |
<Button onClick={toggleOpenState} name={isOpen ? "Close" : "Open"} /> | |
</div> | |
); | |
}; | |
/********************** End Toggle Function *******************/ | |
export default Toggle; | |
/********************** Reducer Function *******************/ | |
const isOpen = (state = false, action) => { | |
if (action.type === "TOGGLE_STATE") { | |
return !state; | |
} | |
return state; | |
} | |
/********************** End Reducer Function *******************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment