mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 00:14:25 +00:00
Implement state contexts
This commit is contained in:
24
frontend/src/contexts/FileContentContext.js
Normal file
24
frontend/src/contexts/FileContentContext.js
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user