Skip to content

Commit

Permalink
fix(react): handle update
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Jun 13, 2020
1 parent afe4cab commit 5f2158f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/bytemd/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export interface EditorProps extends bytemd.EditorProps {
onChange?(value: string): void;
}

export const Editor: React.FC<EditorProps> = (props) => {
export const Editor: React.FC<EditorProps> = ({
children,
onChange,
...props
}) => {
const ed = useRef<bytemd.Editor>();
const el = useRef<HTMLDivElement>(null);

Expand All @@ -18,13 +22,16 @@ export const Editor: React.FC<EditorProps> = (props) => {
props,
});
editor.$on('change', (e) => {
if (props.onChange) {
props.onChange(e.detail.value);
}
if (onChange) onChange(e.detail.value);
});
ed.current = editor;
}, [el.current]);

useEffect(() => {
// TODO: performance
ed.current?.$set(props);
}, [props]);

return <div ref={el}></div>;
};

Expand Down

0 comments on commit 5f2158f

Please sign in to comment.