Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

currentCol bug-fix #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function App() {
const [infoModalIsOpen, setInfoModalIsOpen] = useState(firstTime)
const [settingsModalIsOpen, setSettingsModalIsOpen] = useState(false)

const currentColRef = useRef();
currentColRef.current = currentCol

const openModal = () => setIsOpen(true)
const closeModal = () => setIsOpen(false)
const handleInfoClose = () => {
Expand Down Expand Up @@ -207,14 +210,15 @@ function App() {
document.activeElement.blur()
setSubmittedInvalidWord(false)
setBoard((prev) => {
if (currentCol > 4) {
if (currentColRef.current > 4) {
return prev
}
const newBoard = [...prev]
newBoard[currentRow][currentCol] = letter
console.log("in addLetter: ", currentColRef.current)
newBoard[currentRow][currentColRef.current] = letter
return newBoard
})
if (currentCol < 5) {
if (currentColRef.current < 5) {
setCurrentCol((prev) => prev + 1)
}
}
Expand All @@ -241,11 +245,11 @@ function App() {

const onDeletePress = () => {
setSubmittedInvalidWord(false)
if (currentCol === 0) return
if (currentColRef.current === 0) return

setBoard((prev) => {
const newBoard = [...prev]
newBoard[currentRow][currentCol - 1] = ''
newBoard[currentRow][currentColRef.current - 1] = ''
return newBoard
})

Expand Down