The processor market is changing. Until the beginning of 2017 Intel's advantage in the gaming segment was so great that there was virtually no competition and Intel had no reason to make significant improvements. The appearance of Ryzen supposed that things were quite equal. However the launch of Ryzen was not without problems (with the inter-core latency discussion, a poor 1080p gaming performance as well as memory support).
Many of these problems have been solved with the successive improvement of the drivers and especially with the appearance of the second generation of Ryzen. But in the meantime many people opted for Intel and obviously the current difference does not justify the cost of a platform change.
i5-8400 has an advantage. You pair it with a decent DDR4 2666 or higher, any B360 mobo, a decent PSU and the stock cooler (or aftermarket cooler that you have from your old computer, and forget about the rest.
The alternative is Ryzen 5 2600x or Ryzen 5 2600. If you do not like the OC then you should choose Ryzen 5 2600x and you will be in a situation similar to the previous one (with the small difference that it is better that you choose a DDR4 FlareX 3200 to obtain everything Ryzen can give).
If you like the OC choose the Ryzen 5 2600 and with an effort on your part you will get the same as with Ryzen 5 2600x. But do not deceive yourself, you will not save money. You will need a very good mobo a very good PSU and a very good cooler (preferably liquid).
Additionally you have to remember that if you want all the characteristics of the second generation of Ryzen you must use a mobo with X470 (more expensive). You can choose to use a first generation mobo (X370, B350 or A320 without OC) but then remember to make sure that your bios is up to date to support the second generation of Ryzen.
I believe that in the gaming segment the price and performance differences are so small that the choice depends many times on specific circumstances of each case.
Of course, if what is going to devote the pc is to video editing or similar, Ryzen has a significant advantage.