All files / atom/pinInput/src/reducer usePinInputReducer.js

100% Statements 6/6
66.66% Branches 2/3
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20            1x 309x   309x   309x 63x     309x        
import {useMemo, useReducer} from 'react'
 
import useMountedState from '@s-ui/react-hooks/lib/useMountedState'
 
import {getInitialPinInputReducerState, pinInputReducer} from './reducer.js'
 
const usePinInputReducer = ({mask, defaultValue, value} = {}) => {
  const isMounted = useMountedState()
 
  const isMountedState = isMounted()
 
  const initialState = useMemo(
    () => (isMountedState ? initialState : getInitialPinInputReducerState({mask, defaultValue, value})),
    [isMountedState] // eslint-disable-line react-hooks/exhaustive-deps
  )
  return useReducer(pinInputReducer, initialState)
}
 
export default usePinInputReducer