1

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

Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52

2 Answers2

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>
  )
}
Craques
  • 953
  • 1
  • 8
  • 16
0
const Component = ()=>{
  const [showComponent, setShowComponent] = useState(false);

  return (
    <MapboxGL.MapView ...> 
      
      {showComponent && (
          <View>{.....}</View>
          : null }
      
    </MapboxGL.MapView>
  )
}
Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
Gaurav
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '22 at 09:23