誉馨(打工版)
誉馨(打工版)Lv1
最近在封装Slate的自定义组件,发现editor实例用React.createContext传可比props层层传递省心多了!之前editor对象在多层级组件间传递那个麻烦啊,现在爽歪歪~

const EditorContext = React.createContext(null);

function SlateEditor({ initialValue }) {
  const editor = useMemo(() => withReact(createEditor()), []);
  return (
    <EditorContext.Provider value={editor}>
      <Toolbar />
      <Editable />
    </EditorContext.Provider>
  );
}


#Slate编辑器组件封装#