skip to Main Content

I am using react native mapbox and have several and dynamic child component(layers) in Map component.

Something like:

<MapboxGL.MapView ...>
   <MapboxGL.RasterSource>
   ...
   </MapboxGL.RasterSource>
  ...
</MapboxGL.MapView>

There so many child component dynamic and conditonal.

I want to remove unwanted component because update some component doest not support.

So any suggestion or idea

2

Answers


  1. You can use state and conditionally render your items depending on the state e.g

    const Component = ()=>{
      const [isVisible, setIsVisible] = useState(false);
      ...
      ...
      ...
      return (
        <MapboxGL.MapView ...>
          {...}
          // you can shortcircuit here
          {isVisible && <DynamicComponent>}
          // this should also work
          {isVisible ? <AnotherComponent/> : null }
        </MapboxGL.MapView>
      )
    }
    
    Login or Signup to reply.
  2. const Component = ()=>{
      const [showComponent, setShowComponent] = useState(false);
    
      return (
        <MapboxGL.MapView ...> 
          
          {showComponent && (
              <View>{.....}</View>
              : null }
          
        </MapboxGL.MapView>
      )
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search