Implement state contexts

This commit is contained in:
2024-10-04 21:21:24 +02:00
parent 402d6b1623
commit 5b946269bc
14 changed files with 334 additions and 250 deletions

View File

@@ -0,0 +1,24 @@
import React, { createContext, useContext } from 'react';
import { useFileContent } from '../hooks/useFileContent';
const FileContentContext = createContext();
export const FileContentProvider = ({ children }) => {
const fileContentHook = useFileContent();
return (
<FileContentContext.Provider value={fileContentHook}>
{children}
</FileContentContext.Provider>
);
};
export const useFileContentContext = () => {
const context = useContext(FileContentContext);
if (!context) {
throw new Error(
'useFileContentContext must be used within a FileContentProvider'
);
}
return context;
};