Skip to content
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

fixed mine component issue #414

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

kshitij430
Copy link
Contributor

This PR closes issue #375 .

Earlier I had raised a PR #386 which did not work as intended. Because it had missing "response" as a dependency in the useEffect call.

The issue that needed to solve was, as during the initial render response is an empty object. based on the empty object the
tasks state was getting updated and as "response" was a dependency it kept on going in a loop.

To solve the issue. I added two checks.

  1. to only call the API when the response is an empty object.
  2. to only update the tasks state when response is not an empty object. meaning we have valid response from the API. (If this check was not added tasks would have been updated by empty object which might have caused more bugs).

To avoid the blinking effect of no tasks found. I had to add checks to see if the response is empty and if the tasks is empty. Only then we can say No tasks found.

Please find the video attached to simulate the working. In the first instance I have used a different url to get the tasks and updated my code accordingly. In the second instance I have used the /self API which for my user returns an empty array.

2023-02-07.00-04-41.mp4

@vercel
Copy link

vercel bot commented Feb 6, 2023

@kshitij430 is attempting to deploy a commit to the RDS-Team Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines +55 to +58
tasks.length > 0 && <div>{CardList(tasks)}</div>
}
{
response?.length == 0 && tasks.length == 0 && <p>No Tasks Found</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the code, this response object holds the tasks array right? so, if yes then why are we even checking the state (task state), why not a simple check of response.length > 0 ? {render tasks} : no tasks, do check if you can do this.

Comment on lines +37 to +38
if (JSON.stringify(response) === "{}") callAPI();
if (JSON.stringify(response) !== "{}") setTasks(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of 2 if's could we not add an if else block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for pointing it out, will do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants