Cramer: Why China had to devalue the yuan

While China's decision to devalue its currency caught many off guard, it was something that needed to be done, CNBC's Jim Cramer said Wednesday.

"China is an exports nation and the exports this Saturday were so horrendous," Cramer said on "Squawk on the Street."

Chinese exports fell 8.3 in July, their largest drop in four months. The top-line figure was also far worse than expected, as economists polled by Reuters believed exports would drop only 1 percent.

Read More Alibaba confident despite China concerns: CEO

On Tuesday, the People's Bank of China devalued the yuan by 2 percent and the Chinese currency continued its slide Wednesday in international trade, hitting a four-year low of 6.5943 against the dollar. Still, China's government said it intervened to prop up the yuan during the final minutes of Asia trading Wednesday, according to a report.

The yuan's fall continued to weigh on global investment markets, as the three major U.S. stock indexes opened about 1 percent lower, while the German DAX and the French CAC 40 both fell more than 2 percent.