President Donald Trump's first visit to New Hampshire as president was soaked in nostalgia for his first campaign — and punctuated with subtle nods to his next one in 2020.

Some Republicans wish he would keep his focus on the election around the corner.

As the GOP faces tremendous challenges in November's midterm elections, Mr. Trump and his allies trained their focus this week on the 2020 presidential primary's premier states. The president has also added new staff to his re-election campaign and struggled at times to share the spotlight with congressional candidates who need his help.

Get Breaking News Delivered to Your Inbox

Mr. Trump's attention to his own political future irked some party loyalists who are furiously preparing for midterm elections this fall, which will decide the House and Senate majorities.

"There is a sense that he should make the congressional campaign committees a bigger priority than his own campaign committee," said Republican strategist Alex Conant.

The early-state focus featured Mr. Trump talking opioids Monday in New Hampshire, first daughter Ivanka Trump on the same day promising action on education and infrastructure in Iowa, and Vice President Mike Pence raising money for New Hampshire Republicans on Thursday.

The president took the stage in New Hampshire's largest city to unveil his plan to battle the nation's opioid crisis. But first, the Republican president mused about early campaign stops in the state that fueled his rise to the presidency a few years earlier.

"It's great to be back here in the great state of New Hampshire," said Mr. Trump, who recalled the hall at Manchester Community College as the site of one of his first events in the state. "This is the room, right here, so I like this room. This has been a good room."

On its face, the event was focused far more on policy than politics. Yet White House officials acknowledged that any visit to New Hampshire was, by nature, politically strategic. They felt it was time for Trump to revisit a battleground state that would carry great import in the 2020 general election and to guard against any possible Republican primary challenger.

One White House official said that Mr. Trump's travel schedule is determined in large part by a desire to repay those who supported him politically in the past. The official was not authorized to publicly discuss the White House's private political motivations and requested anonymity.

Mr. Trump hosted his first campaign rally a month after taking office. His re-election campaign aired its first television ad three months later. He held his first 2020 fundraiser the month after that. And earlier this month, he named a re-election campaign manager.

"A lot of people wish the midterms were his singular focus and he wouldn't worry about his re-election right now," Conant said.

Mr. Trump hasn't ignored the party's midterm efforts, however.

The president helped generate record fundraising totals for the Republican National Committee. He hosted a fundraiser for Missouri's Republican Senate candidate last week and he's set to host another for the House GOP campaign committee this week.

Mr. Trump also campaigned for Pennsylvania Republican Rick Saconne ahead of last week's special congressional election, although the president said little about the GOP candidate during the appearance.

The early state focus comes as Mr. Trump eyes an uncertain political future.

Up against the prospect of a GOP electoral disaster this fall — and a special counsel's investigation — Democrats and even some Republicans are already preparing to challenge him in 2020. Just three days before Mr. Trump's visit, Republican Sen. Jeff Flake of Arizona earned a standing ovation after telling New Hampshire voters that he might launch a primary challenge against the president.

"A brush fire for the White House could turn into a full-on wild fire if they're not careful," said Matt Moore, who previously led the state GOP in South Carolina, which traditionally hosts the third presidential primary contest after Iowa and New Hampshire.

"Particularly in the early primary states, activists can easily feel jilted if they don't feel the love from the White House. This White House is smart to begin its outreach early," Moore said.

A sitting president hasn't lost a primary election in modern history. But even if Mr. Trump sails through the 2020 primary, he is expected to face stiff competition from the Democratic nominee later that year in both New Hampshire and Iowa, which are considered general election battlegrounds.

Mr. Trump came in second place in Iowa's presidential caucus in 2016. His first primary contest victory didn't come until a week later in New Hampshire. While he lost narrowly the Granite State in the general election, Trump's inner circle has always reminisced fondly about New Hampshire, believing that it wasn't until he won there that they felt like he had a shot at capturing the presidential nomination.

From the stage in Manchester, Mr. Trump made no mention of his re-election bid, save a passing reference to serving "seven more years" in office. Yet politics permeated the event. More than 100 protesters stood outside in sub-freezing temperatures to jeer the president's motorcade.

Republican strategist Rick Tyler called Mr. Trump's early state focus "premature and unconventional."

"But that doesn't matter to him," Tyler said. "The bigger question the Republican Party has to answer is how do they make Trump an asset in 2018? The answer is I don't know."