mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
add front end code (#27)
This commit is contained in:
27
web/reducer.js
Normal file
27
web/reducer.js
Normal file
@ -0,0 +1,27 @@
|
||||
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 }
|
||||
|
||||
Reference in New Issue
Block a user