Help with.. Don't allow tokens to be sent to the contract

What is the best practice for add a blocking of transfer tokens to the contract address. I'm looking for ERC20Upgradeable

is this OK?:

 modifier rejectTokensToContract(address to) {
	require(to != address(this), "Losing gravity, check recipient address");

function _beforeTokenTransfer(address from, address to, uint256 amount)
	override(ERC20Upgradeable, ERC20SnapshotUpgradeable)
	super._beforeTokenTransfer(from, to, amount);

hey @rayconnection
I am not sure to have understood the question.
Do you want to block your token to be sent to contracts?
Or you want to block any incoming token in your contract?

I just thought about it.. The idea was to block the receipt of any token from outside, but this function blocks transferring only the token of this contact...
How can block the sent(reception) any incoming and my token in the contact?

You can't block tokens to come in.
Smart contracts can't know when a token is sent to them. They can only know when native token of that chain is sent (eg.BNB, ETH, MATIC, AVAX...)

Thank you for answer. At least, the function of stopping the receipt of a personal token of the contract is useful? is there are a practice now to use the function that I wrote above?

for push up the topic, again I will ask a question. Someone could help me, it is advisable to use this function for block sending the tokens on their own contract?