Perspective camera limit zooming not working properly

I’m trying to limit the zoom when a button is off. When it is off limit the zoom and when it is on there is not limit for zooming.It should work as it is. limit is working when the button is off but when it is on it is not reseting the limit.
I’m using this code:

  useEffect(()=>{
    if(!props.keyplanOpen || !props.unitOpen || !props.miscOpen){
      controls.minDistance=100
      controls.maxDistance=300 
      
    }else{
      controls.minDistance=0
      controls.maxDistance=0
    }
  },[props.unitOpen,props.keyplanOpen,props.miscOpen])

I’m using perspective camera with orbitcontrols in react three fiber. Thanks

Have you tried controls.update();
after a controls property change?

tried that. Not working. It is still set to minDistance=100, maxDistance=100. What I want is if any of this button is off then limit the zoom. That is limiting the zoom but its not being reset when the button is on.

@Tanjil_Hossain with min and max distance you limit the dolly of the camera not the zoom. If you indeed are talking about zoom and is not a confusion of concepts you should use maxZoom and minZoom assuming you are using an orthographic and not a perspective one.

If you are using a perspective camera I bet your conditional is the one failing or you never reach that piece of code. Log everything to check it:

useEffect(()=>{
    console.log('useEffectEnter');
    console.log(props.keyplanOpen, props.unitOpen, props.miscOpen);
    if(!props.keyplanOpen || !props.unitOpen || !props.miscOpen){
      console.log('Limit camera distances');
      controls.minDistance=100
      controls.maxDistance=300 
      console.log(controls);
    }else{
      controls.minDistance=0
      controls.maxDistance=0
    }
  },[props.unitOpen,props.keyplanOpen,props.miscOpen])

Basically, I’m trying to limit the scrolling effect on the model. When I’m scrolling the mouse wheel it’s going inside of the model and scrolling out at a certain time shows the whole area that I don’t want.
What I want is to limit the scrolling effect. It should stay out of the building and not go inside of the building as well as zooming or dolly whatever you say should be in a limit. you can see in the video