1 year ago

#379263

test-img

Say u

Modal not showing when setting visibility in UseEffect call

Hi so I am trying to conditionally set the visibility of a modal (react-native-modal) in the useEffect function of one of my components. The issue is the modal sometimes doesn't show even though the visibility is set to true. Also when this happens it prevents me from interacting with the page below it pretty much breaking the app and causing the user to have to clear it before proceeding.

Here is how i render my modal in the return(the view is just a placeholder):

<Modal
    isVisible={guidanceVisible}
    style={styles.guidanceModalContainer}
    onBackdropPress={() => null}
    backdropOpacity={.75}
  >
    <View style={{
      width: '100%',
      height: '100%',
      backgroundColor: 'green'
    }}/>
  </Modal>

Initialize State: const [guidanceVisible, setGuidanceVisible] = useState(false);

setGuidance in useEffect:

useEffect(() => {
if(myPosts.length > 1){
  // setTimeout(() => {
    setGuidanceVisible(true)
  // }, 500)
}}, []);

As you can see I have already tried using a setTimeout but then I run into a different error. If a user interacts with the page while the timeout is waiting to be called then the same issue as before with the page being uninteractable happens again. Please let me know if you have any ideas or spot any mistakes. Thanks ahead of time!

javascript

reactjs

react-native

react-native-modal

0 Answers

Your Answer

Accepted video resources