When WWI broke out in Europe, the US was officially neutral, then helping supply its historical allies, then - after three years - entering directly. One lesson, right off the bat, is that big conflicts have a way of pulling in other countries, forcing folks to pick a side even if they're initially neutral. This has been part of the reason larger countries like the US - with many trade and military relationships around the globe, and people from all over the planet - see it in their interest to defuse and shape conflicts before they become hot wars. In a globally-connected world, strict isolationism is not a realistic option. Since the US cannot be active on every front in every theater, it needs military allies, sympathetic economies and a vision which convinces many of the world's people and countries that they're stronger allied with us than with our rivals. Trump's rhetoric and actions serve to jeopardize many of the relationships that need strengthening.
Echoes of this may be found today in the insistence by Trump and Putin that Ukraine pay them half its resources (Trump) plus half its land (Putin). Since it couldn't pay its bills and had no hopes of interacting positively with the outside world, the German economy collapsed, the politics turned xenophobic, and the fascist mythology of "once-great empire beaten down by its neighbors" motivated the rise of Hitler and a desire to conquer its neighbors. The lesson, seemingly lost on Trump, is that brutalizing already-downtrodden folks can backfire: Eventually they'll fight back. The lesson Trump _did_ learn is that xenophobia and economic oppression can be powerful motivating factors convincing folks to unify behind a dictator.
Then World War II began. As with WWI, the US largely stayed out of it at first, then got drawn in when it became clear that the Axis wouldn't let us sit on the sidelines supplying our friends. Of course, Trump's modern "America First" rhetoric echoes the isolationists of WWII, saying we shouldn't fight for Europe / Ukraine. Apparently unaware of the contradictions, he also claims the right to launch unprovoked military invasions of allies like Canada, Panama, and Denmark (which owns Greenland). As with expansionist WWII powers Japan and Germany, modern Russian and Chinese imperialism threatens first their immediate neighbors - many of whom are US military allies and economic trading partners. As with WWII, there is no reason to expect the US's rivals to stop expanding of their own accord, or to refrain from threatening US interests. If the US wants to maintain its alliances and stop Chinese & Russian expansionism, it needs to help nominal allies resist invasion. Sino-Russian policy toward the US might be summed up as "divide and conquer": weaken our allies directly, weaken their ties to the US, break up their alliances with each other, and foster isolationism and xenophobia and division within the US. The counter to this is to tighten alliances, shun disinformation, and to ease lower-priority conflicts in favor of cooperation around mutual interests - military and economic strength, climate change, refugee crises and world health are all difficult problems where a smart American government would seek cooperation with others who feel threatened by expansionist empires. Donald Trump, of course, disdains cooperation and wants to run an expansionist empire himself.
The Cold War followed WWII, and brought us to the modern era with three large powers: the US, China and Russia. For a long time, the US's military and economic strength was unchallenged - largely _because_ of its economic and military ties to Europe and the Western Hemisphere. We fought (and won) two World Wars, but in neither was the US fighting alone. In neither was the majority of the US's territory under direct threat. We benefitted from the scientists and soldiers and industries of our allies, as well as from our opponents having to cross through allied territory to reach us. Although Trump talks about the US providing protection to Europe, the only time NATO's mutual-defense pact has been invoked has been after 9/11, when our allies came to our aid. The US initiated two long, costly, unproductive wars in the Middle East without clearly-articulated goals, or an exit strategy. But Europe stayed with us through them, and the consensus afterwards was that we should focus on providing arms and intelligence to military conflicts, but letting democratically-elected governments choose their own ways forward.
The US and other powers sought to limit the number of unsecured nuclear weapons, and to limit the number of nuclear powers who might start a war or sell nuclear weapons to terrorists. In 1994, as part of this effort, the US, UK and Russia jointly supported Ukraine's territorial sovereignty in exchange for Ukraine giving up its nukes. (See the "Budapest Memorandum".) Russia's guarantee was violated in 2014 when Russia invaded Crimea, triggering economic and diplomatic sanctions against Russia, per the Budapest Memorandum. Per the agreement, the US and its allies have provided support to Ukraine to fight a war of resistance against its larger, better-armed, aggressive neighbor. Russian propaganda and Donald Trump have obviously blamed Ukraine for this. Also, Trump's resistance to providing the obligatory and Congressionally-mandated aid to Ukraine led to his first impeachment.
In addition to reinforcing a reputation as a country that stands by our agreements, aiding Ukraine helps to contain an aggressive and belligerent Russia. Europe has other reasons as well, of course - Russia is their neighbor too, and Russia's imperialist behavior in Ukraine has motivated the rest of the continent to start building up its military in case it needs to resist invasion as well. This also led to several additional countries joining NATO - the opposite of Russia's stated goal in attacking Ukraine. Although Putin claims NATO expansion drove him to invade Ukraine, the Eastern European countries which joined did so of their own volition - because they feared Russian expansionism, and because of Russian attacks in Georgia and the former Soviet satellites. NATO countries outside the US have long spent less on their defense budgets than the alliance's agreement calls for, but Russia's invasion of Ukraine is motivating them to spend more. Donald Trump also wants to take credit for that, but he can only do so in a perversion of the facts: By being an unreliable partner, he has undermined the US's reputation of strength and honesty, and forced our allies to consider the US as a well-armed, aggressive, manipulative Russian asset.
On the subject of recouping our expenditures on defending Ukraine from Russia: Much of the military aid we've given them has been spent in the US - sourced from US-based companies and workers. Either we send them second-hand goods from our military (and upgrade our military in the process), or we contract with domestic companies to build ammunition & equipment for Ukraine, then send the finished products directly. We spend more in total dollar amount than other countries in aiding Ukraine, but less as a percentage of GDP. Our European allies are more committed to defending their backyard than we are, and they know it. Regarding NATO member states' agreement to spend 2% of their domestic GDP on defense: Traditionally, that has been mostly split between goods they produce for themselves and goods they buy from other member states. It is not, as Trump seems to think, required to be a protection fee paid to the US. Among the reasons to buy from allies are not only economic benefits, but also interoperability of equipment and ease of cross-training. If the US is leaving NATO, or trying to charge it protection fees so it doesn't get conquered by Russia, the other member countries will try to spend more of their defense budgets buying arms domestically and from each other - not from the US companies they've helped support thus far. It will take some years for them to make that shift, but Donald Trump has repeatedly reminded them why they should.