I read about this brilliant insight from an interview with Tucker Max:

When you’re affected by some hateful online comment, it’s because you’re attaching a piece of your identity to it.

The question is not how to deal with it superficially, but to ask yourself what’s missing in your life so you can work on it and thus not further attach yourself to things.