ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
49 lines • 1.55 kB
JavaScript
import * as React from 'react';
import { useCallback, useMemo, useState } from 'react';
import { PreferencesEditorContext, } from "./PreferencesEditorContext.js";
export const PreferencesEditorContextProvider = ({ children }) => {
const [isEnabled, setIsEnabled] = useState(false);
const [editor, setEditor] = useState(null);
const [preferenceKey, setPreferenceKey] = useState(null);
const [path, setPath] = useState(null);
const [title, setTitleString] = useState(null);
const [titleOptions, setTitleOptions] = useState();
const enable = useCallback(() => setIsEnabled(true), []);
const disable = useCallback(() => {
setIsEnabled(false);
setEditor(null);
}, []);
const setTitle = useCallback((title, titleOptions) => {
setTitleString(title);
setTitleOptions(titleOptions);
}, []);
const context = useMemo(() => {
return {
editor,
setEditor,
preferenceKey,
setPreferenceKey,
title,
titleOptions,
setTitle,
isEnabled,
disable,
enable,
path,
setPath,
};
}, [
disable,
enable,
editor,
preferenceKey,
isEnabled,
path,
setPath,
title,
titleOptions,
setTitle,
]);
return (React.createElement(PreferencesEditorContext.Provider, { value: context }, children));
};
//# sourceMappingURL=PreferencesEditorContextProvider.js.map