Why not? Why is it better to copy and paste code from stack overflow than to pull in a dependency that does the same thing?

You can only pick the parts that you need and aren't now exposed to a supply chain attack. You can also easily adapt the code to your needs easily, especially as your needs change.

https://www.youtube.com/watch?v=PAAkCSZUG1c&t=568s