Trex (TREX -0.93%) used cost controls to deliver an earnings beat despite lower-than-expected revenue, but investors were more focused on the company's weak forecast for future demand.

The stock is plunging post earnings, down 21% as of 1:30 p.m. ET.

Lagging revenue in a tough market

Trex is a maker of composite decking and wood alternatives. The company is tied to the housing and remodeling industries, and its value proposition includes a higher up-front cost in exchange for lower ongoing maintenance costs.

In a tough housing market, where consumers are feeling the pinch of higher inflation, it is no surprise that Trex is experiencing some headwinds. The company earned $0.80 per share in the quarter, better than the $0.78 per share consensus estimate, but revenue of $376 million fell short of the $388 million expectation.

Higher utilization, cost cuts, and other efficiency initiatives drove an 80-point expansion in gross margin to 44.7%, driving the earnings beat. But Trex is not feeling upbeat about the quarters to come. The company guided for third-quarter revenue of $220 million to $230 million, well below the $290 million consensus. For the full year, Trex expects sales of $1.13 billion to $1.15 billion compared to the $1.24 billion consensus estimate.

"Given the uncertain economic outlook and the softness in the entry-level segment, we are taking a measured approach to adjusting our sales guidance for the full year," CEO Bryan Fairbanks said in a statement.

Is Trex stock a buy?

Sales were up year over year, just not at the rate that analysts had hoped. Trex is a market leader in an attractive category, but it is tough to say how soon these headwinds will subside.

In theory, the much-discussed rate cuts seemingly on the horizon should help boost housing and remodeling demand. However, significant uncertainty about consumer health remains, and Trex's products tend to be more expensive than wood alternatives.

Trex remains an attractive long-term investment, and patient investors who are willing to wait out the slump could do well here. However, buyers should not expect an overnight rebound in the stock.