mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-04-21 21:50:02 +08:00
28 lines
666 B
JavaScript
28 lines
666 B
JavaScript
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 }
|
|
|