BEIJING — For China, President Trump’s scrapping of the American-brokered Pacific trade agreement is a chance to extend Beijing’s economic and political influence. And it is an opportunity to deepen ties with its neighbors in Asia.

But with a cooling economy at home and a looming leadership shake-up, the last thing President Xi Jinping wants is a trade war, though officials are girding for that possibility. Rather, China’s leaders crave stability and predictability.

Early signs indicate they may not get their wish. The Chinese fear that if Mr. Trump was willing to toss aside years of delicate negotiations with allies and decades of American trade policy, he could also go his own way on issues he has staked out with Beijing, including Taiwan and the South China Sea.

As if to bolster that point, on Monday — the same day that Mr. Trump withdrew from the Trans-Pacific Partnership, the 12-nation trade agreement — his spokesman said the United States would prevent China from accessing islands it claims in the South China Sea, a threat that one nationalist Chinese newspaper had already warned would mean war.