@@ -6,13 +6,13 @@ import { useCallback, useEffect, useMemo } from 'react'
66interface Props {
77 orientation : 'white' | 'black'
88 setOrientation : ( orientation : 'white' | 'black' ) => void
9- currentNode : GameNode
9+ currentNode : GameNode | null
1010 plyCount : number
1111 goToNode : ( node : GameNode ) => void
1212 goToNextNode : ( ) => void
1313 goToPreviousNode : ( ) => void
1414 goToRootNode : ( ) => void
15- gameTree : GameTree
15+ gameTree : GameTree | null
1616 setCurrentMove ?: ( move : [ string , string ] | null ) => void
1717 disableFlip ?: boolean
1818 disablePrevious ?: boolean
@@ -43,17 +43,11 @@ export const BoardController: React.FC<Props> = ({
4343 } , [ orientation , setOrientation ] )
4444
4545 const hasPrevious = useMemo ( ( ) => {
46- if ( currentNode !== undefined ) {
47- return ! ! currentNode ?. parent
48- }
49- return false
46+ return ! ! currentNode ?. parent
5047 } , [ currentNode ] )
5148
5249 const hasNext = useMemo ( ( ) => {
53- if ( currentNode !== undefined ) {
54- return ! ! currentNode ?. mainChild
55- }
56- return false
50+ return ! ! currentNode ?. mainChild
5751 } , [ currentNode ] )
5852
5953 const getFirst = useCallback ( ( ) => {
@@ -72,6 +66,8 @@ export const BoardController: React.FC<Props> = ({
7266 } , [ goToNextNode , setCurrentMove ] )
7367
7468 const getLast = useCallback ( ( ) => {
69+ if ( ! currentNode ) return
70+
7571 let lastNode = currentNode
7672 while ( lastNode ?. mainChild ) {
7773 lastNode = lastNode . mainChild
0 commit comments