If player is restricted on a value, why does it not "snap" back?

I used a Vector2 player restriction script that I changed to Vector3. In doing so I came across an issue in the corners of the game space. You can continue to increase and decrease on the X axis past the restriction.

float currPosX = transform.position.x;
float currPosY = transform.position.y;
float currPosZ = transform.position.z;


if (transform.position.x <= -10) 
{
 transform.position = new Vector3(-10f, currPosY, currPosZ);
}
else if (transform.position.x >= 10) 
{
 transform.position = new Vector3(10f, currPosY, currPosZ);
}
else if (transform.position.z <= -10) 
{
 transform.position = new Vector3(currPosX , currPosY, -10f);
}
else if (transform.position.z >= 10) 
{
 transform.position = new Vector3(currPosX , currPosY, 10f);
}

also tried to alter using && || statements based off other axis, probably logic error though.

Try this:

float currPosX = transform.position.x;
float currPosY = transform.position.y;
float currPosZ = transform.position.z;

currPosX = Mathf.Clamp(currPosX,-10f,10f);
currPosZ = Mathf.Clamp(currPosZ, -10f, 10f);
transform.position = new Vector3(currPosX, currPosY, currPosZ);