File size: 666 Bytes
ab2ded1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React, { useReducer } from 'react'
const CHANGE_LOCALE = 'CHANGE_LOCALE'

const mainContext = React.createContext()

const reducer = (state, action) => {
    switch (action.type) {
        case CHANGE_LOCALE:
            return { ...state, locale: action.locale || 'zh' }
        default:
            return state
    }
}

const ContextProvider = (props) => {
    const [state, dispatch] = useReducer(reducer, {
        locale: 'zh'
    })
    return (
        <mainContext.Provider value={{ state, dispatch }}>

            {props.children}

        </mainContext.Provider>
    )
}

export { reducer, mainContext, ContextProvider }