Hide/Show components in react native

后端 未结 24 2022
囚心锁ツ
囚心锁ツ 2020-12-07 08:43

I\'m really new to React Native and I\'m wondering how can I hide/show a component.
Here\'s my test case:



        
24条回答
  •  不思量自难忘°
    2020-12-07 09:26

    // You can use a state to control wether the component is showing or not
    const [show, setShow] = useState(false); // By default won't show
    
    // In return(
    {
        show && 
    }
    
    /* Use this to toggle the state, this could be in a function in the 
    main javascript or could be triggered by an onPress */
    
    show == true ? setShow(false) : setShow(true)
    
    // Example:
    const triggerComponent = () => {
        show == true ? setShow(false) : setShow(true)
    }
    
    // Or
     {show == true ? setShow(false) : setShow(true)}}/>
    
    

提交回复
热议问题