modules/core/state/context.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 24
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
mnd 2
bc 2
fnc 0
dl 0
loc 24
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
/* istanbul ignore file */
2
import React from 'react'
3
4
const StateContext = React.createContext()
5
const DispatchContext = React.createContext()
6
7
const useState = () => {
8
  const context = React.useContext(StateContext)
9
  if (context === undefined) {
10
    throw new Error('useState must be used within a Provider')
11
  }
12
  return context
13
}
14
15
const useDispatch = () => {
16
  const context = React.useContext(DispatchContext)
17
  if (context === undefined) {
18
    throw new Error('useDispatch must be used within a Provider')
19
  }
20
  return context
21
}
22
23
export { StateContext, DispatchContext, useState, useDispatch }
24