Skip to content

Commit

Permalink
fix: corret the dragpreview example by adding an effect dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
darthtrevino committed Mar 26, 2019
1 parent 7ce51e4 commit a608c5e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
@@ -1,4 +1,4 @@
import React, { memo } from 'react'
import React from 'react'

const styles: React.CSSProperties = {
border: '1px dashed gray',
Expand All @@ -11,9 +11,9 @@ export interface BoxProps {
yellow?: boolean
}

const Box: React.FC<BoxProps> = memo(({ title, yellow }) => {
const Box: React.FC<BoxProps> = ({ title, yellow }) => {
const backgroundColor = yellow ? 'yellow' : 'white'
return <div style={{ ...styles, backgroundColor }}>{title}</div>
})
}

export default Box
@@ -1,4 +1,4 @@
import React, { useState, useEffect, memo } from 'react'
import React, { useState, useEffect } from 'react'
import Box from './Box'

const styles = {
Expand All @@ -11,19 +11,24 @@ export interface BoxDragPreviewProps {
title: string
}

const BoxDragPreview: React.FC<BoxDragPreviewProps> = memo(({ title }) => {
const BoxDragPreview: React.FC<BoxDragPreviewProps> = ({ title }) => {
const [tickTock, setTickTock] = useState(false)

useEffect(function subscribeToIntervalTick() {
const interval = setInterval(() => setTickTock(!tickTock), 500)
return () => clearInterval(interval)
}, [])
useEffect(
function subscribeToIntervalTick() {
const interval = setInterval(() => {
setTickTock(!tickTock)
}, 500)
return () => clearInterval(interval)
},
[tickTock],
)

return (
<div style={styles}>
<Box title={title} yellow={tickTock} />
</div>
)
})
}

export default BoxDragPreview
Expand Up @@ -49,7 +49,7 @@ export interface CustomDragLayerProps {
snapToGrid: boolean
}

const CustomDragLayer: React.SFC<CustomDragLayerProps> = props => {
const CustomDragLayer: React.FC<CustomDragLayerProps> = props => {
const { item, itemType, isDragging } = props

function renderItem() {
Expand Down

0 comments on commit a608c5e

Please sign in to comment.