It can happen even to the best players. You left a pawn or a piece unprotected and the opponent grabbed it, or you missed a fork, pin or X-ray, or perhaps one of your pieces was overloaded. Your opponent takes advantage of your oversight and wins material. Now what?
First piece of advice: Do not resign! If it is a rapid or blitz game, your opponent may also make a similar or even biggest mistake, especially under severe time pressure.
But what if it is a "classical" game where your opponent has plenty of time?
In that case, one should react as follows.
Take a deep breath. If possible, leave your table, have a cup of water, clear your mind. Then look at the chessboard and try to see.
Is it possible to get back some of the material? For example you blundered your queen, but in exchange you can get back rook and bishop. Still you are behind, but perhaps, especially if your pieces are "active", you still have a chance.
Is any of your pawns near promotion? Can you win back some material, or at least tie down your opponent's pieces, by threatening a promotion?
If there is no way to recover material, is there any way that you have some other compensation? Your opponent may have an extra rook, but it might be constrained and thus useless. Or perhaps your opponent's king may be in imminent danger, and as a result you may end u having at least a perpetual check.
If none of the above works, and your opponent has a really winning position: could there be a combination, that under best play cannot help you win, but your opponent would need to find responses that are usually not among the moves one usually considers. (Keep in mind that on average one is faced with 20-40 possible choices per move, but even top players rarely consider more than five of them).
If even that does not work, try "psychological warfare". Frustrate your opponent by continuing the fight, so your opponent may decide making unsound exchanges that might end up with you on top. Your opponent thinks they reached a winning finale, but it might not be so winning as they thought.
On the flip side. If you are the beneficiary of an opponent's oversight, it is no time to relax and celebrate! In fact you must be doubly cautious, you do not want to lose a winning game! Double check and triple check every one of your moves, the win is not automatic. If you have enough time, consider every one of your possible options, would it give your opponent a chance for a combination.