Files
suwayomi-material-you-webui/src/components/library/LibraryOptionsProvider.tsx

25 lines
952 B
TypeScript
Raw Normal View History

2022-03-03 18:19:01 +05:30
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2022-03-03 18:19:01 +05:30
import React, { useMemo } from 'react';
import { LibraryOptions } from '@/typings';
2023-10-28 00:32:02 +02:00
import { useLocalStorage } from '@/util/useLocalStorage';
import { LibraryOptionsContext, DefaultLibraryOptions } from '@/components/context/LibraryOptionsContext';
2022-03-03 18:19:01 +05:30
interface IProps {
children: React.ReactNode;
}
2023-10-28 00:32:02 +02:00
export const LibraryOptionsContextProvider: React.FC<IProps> = ({ children }) => {
const [options, setOptions] = useLocalStorage<LibraryOptions>('libraryOptions', DefaultLibraryOptions);
const value = useMemo(() => ({ options, setOptions }), [options, setOptions]);
return <LibraryOptionsContext.Provider value={value}>{children}</LibraryOptionsContext.Provider>;
};