-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module #2 (Tahsina Bintay Azam) #31
base: module-2
Are you sure you want to change the base?
Conversation
} | ||
setPoison((currentPoison) => [...currentPoison, newPoison]); | ||
}, [isFood, isSnake]); | ||
//removing poison |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you push the code? it's not obvious from here what's causing the issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@royantar0311 I have pushed the code into
#35 ,
can you tell me what's wrong there?
No description provided.