Skip to content
Snippets Groups Projects
Commit b6acb9c4 authored by chris's avatar chris
Browse files

didn't rerender tools while typing

parent 591e03b1
No related branches found
No related tags found
1 merge request!188Fix tool rerenders
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import React, { useContext, useMemo } from 'react'; import React, { useContext, useMemo, useState } from 'react';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import MenuButton from '../ui/buttons/MenuButton'; import MenuButton from '../ui/buttons/MenuButton';
...@@ -16,9 +16,9 @@ const Button = ({ view = {}, item }) => { ...@@ -16,9 +16,9 @@ const Button = ({ view = {}, item }) => {
const { dispatch, state } = view; const { dispatch, state } = view;
const handleMouseDown = e => { const handleMouseDown = (e, editorState, editorDispatch) => {
e.preventDefault(); e.preventDefault();
run(state, dispatch); run(editorState, dispatch);
}; };
const isActive = active && active(state, activeViewId); const isActive = active && active(state, activeViewId);
...@@ -33,11 +33,13 @@ const Button = ({ view = {}, item }) => { ...@@ -33,11 +33,13 @@ const Button = ({ view = {}, item }) => {
disabled={isDisabled} disabled={isDisabled}
iconName={icon} iconName={icon}
label={label} label={label}
onMouseDown={handleMouseDown} onMouseDown={(e, editorState, editorDispatch) =>
handleMouseDown(e, view.state, view.dispatch)
}
title={title} title={title}
/> />
), ),
[], [isActive, isDisabled],
); );
return MenuButtonComponent; return MenuButtonComponent;
......
...@@ -78,7 +78,6 @@ const MenuButton = props => { ...@@ -78,7 +78,6 @@ const MenuButton = props => {
title, title,
onMouseDown, onMouseDown,
} = props; } = props;
console.log('here?');
return ( return (
<Wrapper <Wrapper
active={active} active={active}
......
import React, { useState } from 'react'; import React, { useMemo } from 'react';
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { ToolGroupComponent, ToolGroups } from 'wax-prosemirror-components'; import { ToolGroupComponent, ToolGroups } from 'wax-prosemirror-components';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
...@@ -61,14 +61,20 @@ class ToolGroup { ...@@ -61,14 +61,20 @@ class ToolGroup {
if (this._toolGroups > 0) { if (this._toolGroups > 0) {
return <ToolGroups toolGroups={this._toolGroups} view={view} />; return <ToolGroups toolGroups={this._toolGroups} view={view} />;
} }
return (
<ToolGroupComponent const MemorizedToolGroupComponent = useMemo(
key={uuidv4()} () => (
view={view} <ToolGroupComponent
tools={this._tools} key={uuidv4()}
title={this.title} view={view}
name={name} tools={this._tools}
/> title={this.title}
name={name}
/>
),
[view],
); );
return MemorizedToolGroupComponent;
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment