Skip to content

Instantly share code, notes, and snippets.

@marco-souza
Created October 31, 2019 14:07
Show Gist options
  • Save marco-souza/264420002da3afd25730533f313a951b to your computer and use it in GitHub Desktop.
Save marco-souza/264420002da3afd25730533f313a951b to your computer and use it in GitHub Desktop.
state = [
action1,
action1,
]
// hook
const useFilterPedingAction = key => state.filter(item => (
item.status === 'pending' &&
item.name === key
))
// usage
const { listActions, getFilteredActions } = useActions()
const listSSHActions = getFilteredActions(listActions, 'ssh')
const { fetchSSHKeys } = useActions()
const { listActions, getFilteredActions } = useActions()
const [previousValues, setPreviousValues] = useState({
ssh: 0,
})
useEffect(() => {
const sshCount = getFilteredActions(listActions, 'keys')
if (sshCount !== previousState.ssh) {
setPreviousValues({
ssh: sshCount,
...previousValues
})
fetchSSHKeys()
}
}, [listActions])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment