Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexsullivan114
Created November 26, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexsullivan114/c7e8ce0afdb1d96d84a47212b9dc8e63 to your computer and use it in GitHub Desktop.
Save alexsullivan114/c7e8ce0afdb1d96d84a47212b9dc8e63 to your computer and use it in GitHub Desktop.
JSX Confusion
const FeatureLayer = ({ id, circular }: { id: string; circular: boolean }) => {
if (circular) {
return (
<MapboxGL.CircleLayer
id={`${id}-circle`}
style={{ circleRadius: 500, circleColor: "black" }}
/>
)
} else {
return (
<MapboxGL.FillLayer id={`${id}-fill`} style={layerStyles.featureFill} />
)
}
}
// This doesn't work
const FillFeature = ({ feature, id, circular }: FillFeatureProps) => {
return (
<MapboxGL.ShapeSource id={id} shape={feature}>
<FeatureLayer id={id} circular={circular} />
</MapboxGL.ShapeSource>
)
}
// This works
const FillFeature = ({ feature, id, circular }: FillFeatureProps) => {
return (
<MapboxGL.ShapeSource id={id} shape={feature}>
{circular ? (
<MapboxGL.CircleLayer
id={`${id}-circle`}
style={{ circleRadius: 50, circleColor: "black" }}
/>
) : (
<MapboxGL.FillLayer id={`${id}-fill`} style={layerStyles.featureFill} />
)}
</MapboxGL.ShapeSource>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment