The question of how long computers live is a hard one to answer, both because it is an ever evolving field, but also because the lifespan of a computer changes depending on your needs. This can be summed up into two categories, how long a computer can physically survive and how long the computer is actually useful for.
At the current time of writing I am sitting on a 7,5 year old laptop and if I could bother with the cost of changing the battery on it, it could most likely last another 7,5 years or more. The reason mainly being that this laptop is a work tool, for writing, running simpler programs and even a few games sometimes. These requirements are unlikely to change for the foreseeable future, so as long as the components inside my computer works, it will still be useful.
This applies to desktop systems even more so, as they are usually way more powerful and therefore overpowered for your current use and therefore will most likely also be overpowered for future programs and games. It did not used to be like this though, it is only because we have reached a plateau where components in computer only improve a few percent every year. It used to be that computer performance doubled every two years aka Moore’s Law.
This means there is quite a span in the utility of computers of the 80’s and 90’s versus modern day ones, where the old computers were useful for a year, maybe two and modern computers can be useful for close to a decade. This is where physical survival of computers shows it’s ugly head, and interferes with the usefulness of computers.
The first computers up until the early 90’s were mostly built like tanks and several examples have indeed survived wars and been used in wars and outer space as is, due to their extreme durability. This coupled with their components being able to be replaced by hand, means that some of these machines have been running for half a century and may even be able to run for another half a century.
This brings us to modern day computers that are if possible even more robust, with a few caveats. Computers from the late 90’s and forward were built by machines, to make them more compact and get more power out of them, which also means they require specialised equipment to repair or can’t even be repaired at all. This fact, planned obsolescence and some components that aren’t very robust, makes for computers that have a much shorter shelf life.
The three biggest culprits responsible for modern computers getting thrown away these days, are mechanical harddrives, laptop batteries and cheap capacitors. Capacitors are probably the only component you have never heard of, it is just an electrical component that stores electricity and thereby protects other components from power loss or a damaging shock.
Sometimes cheap parts are used as part of planned obsolescence, but both mechanical harddrives and laptop batteries are also only able to be made to a certain standard, limiting their max lifespan to 5-10 years before they begin to fail. Both of these components can be replaced and give the computer another 5-10 years of life, but due to fast cheap manufacturing and partly due to planned obsolescence, it is usually cheaper to just buy a new device and get the extra performance boost and/or better battery life as well.