A question, is there still a chance of infinite loop if the recursive function fetchBook returns the same book every time? May be we need another stronger base case. Or it may be handled in the back end by ensuring that the book is never repeated.
A question, is there still a chance of infinite loop if the recursive function fetchBook returns the same book every time?
Very good question. To tell the truth, I'm not completely sure. I think it wouldn't be an infinite loop, but it'd run twice (once after the component is mounted and once after the state is updated), which is still undesirable and should be addressed. I'll double-check when I get the chance, though.
EDIT: Okay, after a quick experiment, it seems to run into an infinite loop even if the data fetched is always the same.
Or it may be handled in the back end by ensuring that the book is never repeated.
We certainly can handle it in the backend. The principle would be the same, keep track of the last book sent and ensure it doesn't get repeated.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi @savagepixie , thanks for the very nice post.
A question, is there still a chance of infinite loop if the recursive function fetchBook returns the same book every time? May be we need another stronger base case. Or it may be handled in the back end by ensuring that the book is never repeated.
Thanks for your reply!
Very good question. To tell the truth, I'm not completely sure. I think it wouldn't be an infinite loop, but it'd run twice (once after the component is mounted and once after the state is updated), which is still undesirable and should be addressed. I'll double-check when I get the chance, though.
EDIT: Okay, after a quick experiment, it seems to run into an infinite loop even if the data fetched is always the same.
We certainly can handle it in the backend. The principle would be the same, keep track of the last book sent and ensure it doesn't get repeated.