mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Dev/jchamish/forgotpassword (#4481)
* Implementation of Forgotten Password Reset * Update webclient/src/hooks/useReduxEffect.tsx Co-authored-by: Zach H <zahalpern+github@gmail.com>
This commit is contained in:
parent
7c27e955d5
commit
73c5956ece
25 changed files with 447 additions and 7 deletions
1
webclient/src/hooks/index.ts
Normal file
1
webclient/src/hooks/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './useReduxEffect';
|
||||
47
webclient/src/hooks/useReduxEffect.tsx
Normal file
47
webclient/src/hooks/useReduxEffect.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
File is adapted from https://github.com/Qeepsake/use-redux-effect under MIT License
|
||||
* @author Aspect Apps Limited
|
||||
* @description
|
||||
*/
|
||||
|
||||
import { useRef, useEffect, DependencyList } from 'react'
|
||||
import { useStore } from 'react-redux'
|
||||
import { castArray } from 'lodash'
|
||||
import { AnyAction } from 'redux'
|
||||
|
||||
export type ReduxEffect = (action: AnyAction) => void
|
||||
|
||||
/**
|
||||
* Subscribes to redux store events
|
||||
*
|
||||
* @param effect
|
||||
* @param type
|
||||
* @param deps
|
||||
*/
|
||||
export function useReduxEffect(
|
||||
effect: ReduxEffect,
|
||||
type: string | string[],
|
||||
deps: DependencyList = [],
|
||||
): void {
|
||||
const currentValue = useRef(null)
|
||||
const store = useStore()
|
||||
|
||||
const handleChange = (): void => {
|
||||
const state = store.getState()
|
||||
const action = state.action
|
||||
const previousValue = currentValue.current
|
||||
currentValue.current = action.count
|
||||
|
||||
if (
|
||||
previousValue !== action.count &&
|
||||
castArray(type).includes(action.type)
|
||||
) {
|
||||
effect(action)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = store.subscribe(handleChange)
|
||||
return (): void => unsubscribe()
|
||||
}, deps)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue