fake-news-chrome-extension icon indicating copy to clipboard operation
fake-news-chrome-extension copied to clipboard

Rendering Layer when not nested in Source

Open kengreim opened this issue 1 month ago • 0 comments

The docs suggest that something like this should work with a Layer component not nested in a Source if you already have a Source with a defined ID elsewhere

<Layer
  sourceId={SOURCE_ID}
  style={{
    type: "line",
    paint: {
      "line-color": "hsl(100, 100%, 50%)",
      "line-width": 2,
    },
  }}
/>

However, to get it to work with no errors from Mapbox GL JS, I have to do the following:

<Layer
  style={{
    source: SOURCE_ID,
    type: "line",
    paint: {
      "line-color": "hsl(100, 100%, 50%)",
      "line-width": 2,
    },
  }}
/>

It looks like the sourceId prop is not actually used. I suggest changing this line to something like below. Also would need to make a note about precedence. Or remove sourceId prop and make the style prop be the only method to specify Source Id.

const sourceId: string = props.sourceId || props.style?.source || useSourceId();

kengreim avatar May 15 '24 18:05 kengreim