deckgl-typings icon indicating copy to clipboard operation
deckgl-typings copied to clipboard

[HELP] - How to pass generic type to OnClick DeckGL

Open SadikMoazzem opened this issue 2 years ago • 3 comments

onClick: <D>(info: PickInfo<D>, e: MouseEvent) => any; 2244:deck.gl__core

RE this guy in the DeckGL Core types, i cant figure out how to pass the "D" Generic type to the prop

Here is a snippet of the code

<DeckGL<any>
  ref={deckRef}
  viewState={mapViewport}
  controller
  layers={deckLayers}
  ContextProvider={MapContext.Provider}
  onWebGLInitialized={setGLContext}
  onClick={<DeviceData>(clickInfo) => {
      console.log(clickInfo)
  }}
/>

SadikMoazzem avatar Jun 06 '22 23:06 SadikMoazzem

Hi @danmarshall , any help on this would be appreciated

SadikMoazzem avatar Jun 08 '22 01:06 SadikMoazzem

H1 @SadikMoazzem , this is quite puzzling. Hopefully another community member can chime in, or you can try Stack Overflow.

Here's the best I can do:

interface DeviceData {
    abc: number;
}
    <DeckGL<any>
        onClick={((clickInfo) => {
            const deviceData = clickInfo.object as unknown as DeviceData;
            console.log(deviceData.abc)
        })}
    />

danmarshall avatar Jun 08 '22 23:06 danmarshall

I'll try that out. Thanks for the quick reply!!

I was assuming as the type for the onClick allowed to pass in a Type<D> that i was just missing a trick

SadikMoazzem avatar Jun 08 '22 23:06 SadikMoazzem