Module #2 (Tahsina Bintay Azam)#31
Module #2 (Tahsina Bintay Azam)#31tahsina-azam wants to merge 4 commits intorecruit-org:module-2from
Conversation
| } | ||
| setPoison((currentPoison) => [...currentPoison, newPoison]); | ||
| }, [isFood, isSnake]); | ||
| //removing poison |
There was a problem hiding this comment.
since adding poison or a food works similarly, why not create a reusable function addObject that takes in an object type (poison/food) and adds to the appropriate state?
There was a problem hiding this comment.
I wonder why I didn't think like that. :"), I will try to add that in the next module.
There was a problem hiding this comment.
I tried adding a new function addObject to add poison or food based on the parameter of that function as you suggested. But looks like there's a little problem with that.
Can you please tell me what's the problem here?
My function:
const addObject = useCallback((type) => {
let newObject = getRandomCell();
while (isSnake(newObject) || isFood(newObject)) {
newObject = getRandomCell();
}
if ((type = "food")) {
setFoods((currentFoods) => [...currentFoods, newObject]);
} else {
setPoison((currentPoison) => [...currentPoison, newObject]);
}
});
There was a problem hiding this comment.
can you push the code? it's not obvious from here what's causing the issues
There was a problem hiding this comment.
Sure. you can find that piece of code in module-3 branch in src/components/hooks/snake.js.
#35
There was a problem hiding this comment.
@royantar0311 I have pushed the code into
#35 ,
can you tell me what's wrong there?
No description provided.