cutelee

refactor: Context 분리

import { Context, createContext } from "react";
export interface ImageLoadContextType {
imageLoad: boolean,
setImageLoad: Function
}
export const ImageLoadContext: Context<ImageLoadContextType> = createContext<ImageLoadContextType>({
imageLoad: false,
setImageLoad: () => {}
});
\ No newline at end of file
import { Context, createContext } from "react";
export interface SubmenuContextType {
visible: boolean,
onChange: Function
}
export const SubmenuContext: Context<SubmenuContextType> = createContext<SubmenuContextType>({
visible: true,
onChange: () => {}
});
\ No newline at end of file
import React, { ChangeEvent } from "react";
import ToastEditor from "tui-image-editor";
import { SubmenuContext } from "../EditorPage";
import { SubmenuContext } from "context/Submenu";
import "./EditorHeader.scss";
......
import React, { useRef, useEffect, useState, Context } from "react";
import React, { useRef, useEffect, useState } from "react";
import ToastEditor from "tui-image-editor";
import EditorHeader from "./EditorHeader";
import { editorOptions } from "utils/editorOptions";
import { ImageLoadContext } from "context/ImageLoad";
import { SubmenuContext } from "context/Submenu";
import "tui-image-editor/dist/tui-image-editor.css";
import "./Editor.scss";
......@@ -12,19 +14,10 @@ import "./EditorPage.scss";
// @ts-ignore
const initialEditor:ToastEditor = new ToastEditor(document.querySelector("#hidden-editor"), editorOptions);
interface SubmenuContextType {
visible: boolean,
onChange: Function
}
export const SubmenuContext: Context<SubmenuContextType> = React.createContext<SubmenuContextType>({
visible: true,
onChange: () => {}
});
function EditorPage() {
const imageEditorRef = useRef<HTMLDivElement>(null);
const [editor, setEditor] = useState(initialEditor);
const [imageLoad, setImageLoad]: [boolean, Function] = useState(false);
const [submenuVisible, setSubmenuVisible] = useState(true);
useEffect(() => {
......@@ -43,8 +36,10 @@ function EditorPage() {
return (
<>
<SubmenuContext.Provider value={{ visible: submenuVisible, onChange: onChangeSubmenuVisible }}>
<EditorHeader editor={editor} imageLoad={false} />
<div className={`my-editor tui-image-editor-container left ${!submenuVisible && "submenu-hidden"}`} ref={imageEditorRef} />
<ImageLoadContext.Provider value={{ imageLoad, setImageLoad }}>
<EditorHeader editor={editor} imageLoad={false} />
<div className={`my-editor tui-image-editor-container left ${!submenuVisible && "submenu-hidden"}`} ref={imageEditorRef} />
</ImageLoadContext.Provider>
</SubmenuContext.Provider>
</>
);
......
import React from "react";
function ImageResizer() {
return (
<div>이미지 크기 변경</div>
......