-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(blockcontainer): memo blocks inside of container to reduce rende…
…rings
- Loading branch information
Showing
2 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {SFBWrapper} from '@snek-at/jaen-shared-ui' | ||
import BlockProvider from '@src/contexts/block' | ||
import {JaenBlock} from '@src/types' | ||
import isEqual from 'lodash/isEqual' | ||
import * as React from 'react' | ||
|
||
type BlockItemProps = { | ||
// block props | ||
containerName: string | ||
position: number | ||
blockName: string | ||
// other props | ||
BlockComponent: JaenBlock | ||
isEditing: boolean | ||
onDelete: (position: number) => void | ||
} | ||
|
||
const BlockItem = React.memo<BlockItemProps>( | ||
({children, BlockComponent, isEditing, onDelete, ...blockProps}) => { | ||
return ( | ||
<BlockProvider {...blockProps}> | ||
<SFBWrapper onDeleteClick={() => onDelete(blockProps.position)}> | ||
<BlockComponent /> | ||
</SFBWrapper> | ||
</BlockProvider> | ||
) | ||
} | ||
) | ||
|
||
export default BlockItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters