Skip to content

Commit

Permalink
#6 Prevent toggling unlinked refs for all pages on click
Browse files Browse the repository at this point in the history
Unlinked refs were being toggled on every page after a single click on
one. This was because the <References> element in Editor.js was not
re-rendering as expected. It was sticking around and the hooks state
was shared among other pages' <References> elements. The calculation
of the unlinked references was only being done on page load, but it was
still unwelcome. Add key prop to differentiate the instances among pages.

Also fix bug where linked references were not showing because of a lapse
syncing code changes with redux.
  • Loading branch information
cofinley committed Feb 14, 2021
1 parent 2d4ca07 commit 00f0e41
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/features/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Editor = ({ blockId, isRoot, isMain, stopRecursion = false }) => {
</div>
}
{isRoot &&
<References block={block} isMain={isMain} />
<References block={block} isMain={isMain} key={block.id} />
}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/features/editor/References.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const References = ({ block, isMain }) => {
const [showUnlinkedRefs, setShowUnlinkedRefs] = useState(false)
const links = useSelector(state => state.links)
const blocks = useSelector(state => state.blocks)
const references = links[block.id]
const references = links.to[block.id]

const linkedReferences = () => {
if (block.parentId || !references || !references.length) {
Expand Down

0 comments on commit 00f0e41

Please sign in to comment.