Judging by historical data, the answer is not entirely correct.
According to The Motley Fool, the stock market has performed well over the long term under both Democratic and Republican administrations.
In terms of average performance, the S&P 500 $SPX has grown 9.8% annually under Democratic presidents, ahead of 6% under Republicans, since 1957.
However, if we look at median growth rates, the market grew by 10.2% under Republicans, and by 8.9% under Democrats.
While members of either party may argue that the stock market performs better under their party, the direct impact of the policies is difficult to measure.
Additionally, presidential terms are subject to the impact of unforeseen events such as the dot-com bubble, the 2008 financial crisis, Covid-19, etc.
As always, market timing is the name of the game, not the president's political party.
The S&P 500's 10.26% compound annual growth rate is clear evidence of this.