ragflow / web /reducer.js
jinhai-2012's picture
Format file format from Windows/dos to Unix (#1949)
aeb6dbc
raw
history blame
599 Bytes
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 { ContextProvider, mainContext, reducer };