Sign in
Log inSign up
Julia Undeutsch

138 likes

·

1.2K reads

19 comments

Abdul-Razak, Jibrilla
Abdul-Razak, Jibrilla
Mar 9, 2023

Learned something new

3
·
·4 replies
Ludiville
Ludiville
Sep 7, 2023

fsdf

·
Kavir Kaycee
Kavir Kaycee
Sep 11, 2023

Not adding the mention in reply example.com

·
Kavir Kaycee
Kavir Kaycee
Sep 11, 2023

Test comment example2.com

·
Kavir Kaycee
Kavir Kaycee
Sep 11, 2023

exam$ple.com

·
Sandeep Panda Test
Sandeep Panda Test
Mar 10, 2023

Pretty interesting! Thanks for your contribution to DebuggingFeb. :)

1
·
Ákos Kőműves
Ákos Kőműves
Mar 10, 2023

Accessibility is super important. I like navigating with keys only.

However, in React, you will most likely not use something like this in production.

The custom hook's useEffect doesn't have a dependency array, meaning it will run after every re-render of the component. If you put a console.log into the useEffect inside your hook, you'll see that initially, it runs 10 times. After adding 10 tasks, it ran 67 times! The other thing is that you don't need that hook - it's just wrapping around useRef anyway.

Because you know you want to re-focus on the listHeadingRef after the user clicks delete, you can just put that code into your deleteTask function.

function deleteTask(id) { const remainingTasks = tasks.filter((task) => id !== task.id); setTasks(remainingTasks); listHeadingRef.current.focus(); }

This will save you from the constantly re-running hook, and you can remove the entire useEffect, making your code easier to understand and change.

Hope this was helpful.

1
·
·4 replies
Julia Undeutsch
Julia Undeutsch
Author
·Mar 10, 2023

Thank you so much for your reply. I will try it out. :) I still have to learn a lot about react, but for this article, accessibility was the main point.

·
Ákos Kőműves
Ákos Kőműves
Mar 10, 2023

It's super important, especially for people learning React, to understand when they need to use certain mechanisms of React and when the same mechanisms are not just useless but even decremental in performance.

So I thought I'd give you some ideas on how you could write better React code, regardless of accessibility.

Thanks for reading my useless code review. 😄

1
·
Julia Undeutsch
Julia Undeutsch
Author
·Mar 12, 2023

Ákos Kőműves Oh no, please don't get me wrong! I appreciate your comment so much ! Only because I know I am not that good at React I wanted the blog post to be about the accessibility issue rather than the code itself, that's all. I already implemented the delete function you posted and checked with dev tools and console.log. Thank you so much for helping me making my code better. :)

1
·
Ákos Kőműves
Ákos Kőműves
Mar 12, 2023

No worries Julia Undeutsch, and thanks for the follow-up. :) I rarely comment on blog posts, but you put much effort into this, so I thought I chime in with something useful. :)

·
Massimo Baffoni
Massimo Baffoni
Mar 10, 2023

Nice to see other developers working on accessibility. I've started writing here for the same reason.

1
·
·1 reply
Julia Undeutsch
Julia Undeutsch
Author
·Mar 10, 2023

That's nice to hear, Massimo.

·
MadCoding7588
MadCoding7588
Mar 10, 2023

i read your blog and it's amazing . I wanted some help , how did you add table of contents to your blog.

1
·
·2 replies
Ayodele Samuel Adebayo
Ayodele Samuel Adebayo
Mar 12, 2023

You can checkout this guide: support.hashnode.com/en/articles/6541597-h…

1
·
Julia Undeutsch
Julia Undeutsch
Author
·Mar 12, 2023

When you are going to publish your post, a panel appear with several settings, like adding SEO, Thumbnail, url, as well as automatically adding a table of content

1
·
Md Faizan Alam
Md Faizan Alam
Mar 12, 2023

Very well documented

1
·
·1 reply
Julia Undeutsch
Julia Undeutsch
Author
·Mar 16, 2023

Thank you :)

·
Yazdun
Yazdun
Mar 12, 2023

Great article Julia! That's an excellent example of making proper use of useRef 👍

1
·