mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Split large contexts
This commit is contained in:
33
frontend/src/contexts/EditorContentContext.js
Normal file
33
frontend/src/contexts/EditorContentContext.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import React, { createContext, useContext, useMemo } from 'react';
|
||||
import { useFileContent } from '../hooks/useFileContent';
|
||||
|
||||
const EditorContentContext = createContext();
|
||||
|
||||
export const EditorContentProvider = ({ children }) => {
|
||||
const { content, handleContentChange, handleSave } = useFileContent();
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
content,
|
||||
handleContentChange,
|
||||
handleSave,
|
||||
}),
|
||||
[content, handleContentChange, handleSave]
|
||||
);
|
||||
|
||||
return (
|
||||
<EditorContentContext.Provider value={value}>
|
||||
{children}
|
||||
</EditorContentContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useEditorContent = () => {
|
||||
const context = useContext(EditorContentContext);
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
'useEditorContent must be used within an EditorContentProvider'
|
||||
);
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user