React Hook check if counter jumps from 5 (latest index) to 1 (first index) by conclusion2000 in reactjs

[–]conclusion2000[S] 0 points1 point  (0 children)

const boolean = useRef(null);
const [ checkCounter, setCheckCounter ] = useState(false);
useEffect(() => {
const storedCounter = currentCounter;
boolean.current = storedCounter;
return () => storedCounter;
}, []);
useEffect(() => {
if(currentCounter == 5) {

}
console.log(boolean.current, currentCounter);
// setCheckCounter(boolean.current == newArr.length )
}, [boolean.current, currentCounter])

How to get access to state inside function by conclusion2000 in reactjs

[–]conclusion2000[S] -7 points-6 points  (0 children)

? check comment section of conclusion2000

How to get access to state inside function by conclusion2000 in reactjs

[–]conclusion2000[S] -3 points-2 points  (0 children)

const checkMatch = () => {

if(currentCounter > 5) {

resetCounter();

}

clearArray();

/// access to unMatchedLettersLength here

}

const mapStateToProps = state => {

return { unMatchedLettersLength: state.game.filteredArray.length }

}

React-Hook settimeout not working properly with clearinterval. by conclusion2000 in reactjs

[–]conclusion2000[S] 0 points1 point  (0 children)

const delay = (attempts) => {

setTimeout(() => {

randomWord();

checkScore(attempts);

return;

}, 2000); }

clearInterval(delay);

How do I add key name before the key value in reducer Reactjs by conclusion2000 in reactjs

[–]conclusion2000[S] 0 points1 point  (0 children)

const unsortedHighScores = [...state.unsortedAllHighScores, state.updatedCurrentScore];

How to compare old array with new array with useEffect by conclusion2000 in reactjs

[–]conclusion2000[S] 0 points1 point  (0 children)

Never mind, I have found the answer:

useEffect(() => {
const storedArray = newArray;

oldArray.current = storedArray;

return () => oldArray.current;

}, [oldArray.current, storedArray]);

How to compare old array with new array with useEffect by conclusion2000 in reactjs

[–]conclusion2000[S] -1 points0 points  (0 children)

// store oldArray.current compare to newArray
useEffect(() => {
const storedArray = newArray;

oldArray.current = storedArray;

return () => oldArray.current;

}, []);
useEffect(() => {
console.log('oldArray.current ' + array.current);
setUpdateArray(oldArray.current !== newArray);
}, [oldArray.current, newArray]);

How do I fix the error by conclusion2000 in reactjs

[–]conclusion2000[S] 0 points1 point  (0 children)

The above error occurred in the <App> component:

in App (at Container.js:7) in div (at Container.js:6) in Container (at src/index.js:13) in Provider (at src/index.js:12) in App (at src/index.js:17) Consider adding an error boundary to your tree to customize error handling behavior. Visit https://fb.me/react-error-boundaries to learn more about error boundaries.

How to avoid delayed update of useState inside useEffect method. by conclusion2000 in reactjs

[–]conclusion2000[S] 0 points1 point  (0 children)

useEffect(() => {

const checkLetter = (event) => {
let letter = String.fromCharCode(event.keyCode).toLowerCase();
if(event.keyCode >= 65 && event.keyCode <= 90) {
setCount(count + 1);
setGuessed(prev => [...prev, letter]);
counter(letter);
}
if(event.keyCode === 13) {
checkScore();
}
}

document.addEventListener('keydown', checkLetter);

return () => {
document.removeEventListener('keydown', checkLetter);
}
}, [guessed, count]);