All eyes are on the market this week as investors await the magic number that means the market has reached a new high. The Down Jones Industrial Average hit it last week, and the S&P 500 is less than 1% off its previous highs, so this week could signal the end of the bear market.

That could be exciting for investors, who've watched the market rise after 2022's bear market. People love to talk about stock market history and what bodes for the future, based on patterns in the past.

But as much as patterns do exist, the market isn't always rational, and there are plenty of factors that could disturb the upward trajectory. While a market crash isn't on everyone's minds right now, it's important to keep in mind how to behave when it does come, because it could occur when you least expect it.

Here are three things you shouldn't do if the market crashes.

1. Don't panic-sell

The most important thing not to do in a market crash is panic-sell. People can get very nervous watching their life savings drop in value, but once you hit the sell button, you can't get it back without starting again from scratch.

Market crashes are often temporary. The market crash in 2020, provoked by a worldwide pandemic, ended up being a total of one-month long before the market bounced back, quickly hitting new highs. There's no way to know how long prices will stay down, but if you can ride it out, it's likely your stocks will recover and go on to reach new heights.

In general, it's best not to sell at all, but there are cases where it could be prudent -- for example, someone close to retirement who needs money on which to live, or a specific expense that can't be delayed. If a market crash is ongoing and you've evaluated your financial position, you might decide to sell some stocks.

The main point is not to panic. Whatever you end up doing, do it with all of the information in front of you.

2. Don't miss new opportunities

Here's where we recall Warren Buffett's famous saying that he's greedy when others are fearful. If you have a long-term mindset, you'll understand that the market goes through ups and downs, peaks and dips. Use the downs and dips as buying opportunities.

A person looking at a stock board.

Image source: Getty Images.

Let's use some examples from the 2020 crash. Starbucks is a great one. It dropped 34% between Feb. 21, 2020 and March 20, 2020, and dropped to a price-to-earnings ratio of 19. If you knew Starbucks' business and opportunities, you might have seen that the stock was a bargain and grabbed some shares. Starbucks stock is now 64% higher than that low.

Another great stock that plummeted in the 2020 crash was Nike, which dropped 33% between Feb. 21, 2020 and March 20, 2020. Since then, it's up 60%.

3. Don't rush in

The flip side of that is that investors could get excited about new opportunities and invest in stocks that turn out not to be good investments. The other side of Warren Buffett's maxim is that he's fearful when others are greedy. If it looks like there are too many opportunities in the market, there probably are.

In particular, after a market crash, not all cheap stocks are bargains. A stock is only a bargain if it's undervalued. If it's cheap because it has no future, an apparent value could really be a value trap.

Investors could feel pressure to buy quickly when prices plunge. But it's better to be late to the game than to be in the wrong game.

Speaking of Buffett, he's done that plenty of times. Take his favorite stock, as an example. Nearly half of the entire Berkshire Hathaway equity portfolio of more than $370 billion is invested in Apple stock, but he took his first position in 2016. He also first bought Amazon stock in 2019.

In both cases, he said he missed the boat. But he doesn't just jump into stocks without thorough research, and he doesn't worry about missing the opportunity. If you really believe in the long-term opportunity, the stock has decades to gain.

Once you can get into this mindset, market crashes won't weigh you down, and you can use a market crash to your advantage.