@hitachivantara/uikit-react-core
Version:
Core React components for the NEXT Design System.
25 lines (24 loc) • 729 B
JavaScript
import { jsx } from "react/jsx-runtime";
import { createContext, useReducer, useMemo } from "react";
const reducer = (state, action) => {
switch (action.type) {
case "setItemFocused":
return { itemFocused: action.itemFocused };
default:
return state;
}
};
const initialState = { itemFocused: void 0, dispatch: void 0 };
const FocusContext = createContext(initialState);
const FocusProvider = ({ children }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const contextValue = useMemo(
() => ({ ...state, dispatch }),
[state, dispatch]
);
return /* @__PURE__ */ jsx(FocusContext.Provider, { value: contextValue, children });
};
export {
FocusContext,
FocusProvider
};