Git Product home page Git Product logo

Comments (7)

hshoff avatar hshoff commented on May 3, 2024 2

@jnelken you probably have something like

onClick={function(event) {
  // ...
}}

when you want

onClick={function(data) {
  return function(event) {
    // ...
  };
}}

from visx.

donpinkus avatar donpinkus commented on May 3, 2024

I suspect this is some bug related to my code, if I find out otherwise will reopen.

from visx.

hshoff avatar hshoff commented on May 3, 2024

Ah this is by design at the moment. props that are functions need to be thunks. I'm still playing around with this part of the api, so this might change in the future. I hope to lock it down in the next week or two.

Here's the fix:

      return (
        <Group key={`bar-${x(d)}`}>
          <Bar
            width={xScale.bandwidth()}
            height={barHeight}
            x={xScale(x(d))}
            y={yMax - barHeight}
            fill="rgba(23, 233, 217, .5)"
-           onClick={ function(){ console.log('bar clicked'); }}
+ .         data={{ x: x(d), y: y(d) }}
+           onClick={data => event => {
               console.log(`bar clicked: ${JSON.stringify(data)}`)
            }}
          />
        </Group>
      );

You can see this in action here:

from visx.

donpinkus avatar donpinkus commented on May 3, 2024

Ah that's interesting.

Is having access to the component's "data" the main motivation for using a thunk here?

from visx.

hshoff avatar hshoff commented on May 3, 2024

Exactly, it's a bit silly in the simple bar graph example. But it's handy for multiple series like BarStack, BarGroup, or Heatmap

from visx.

nfcampos avatar nfcampos commented on May 3, 2024

why not provide the data as this? or as a 2nd argument?

from visx.

jnelken avatar jnelken commented on May 3, 2024

Can we open this back up? It is still not available. It is still called on render for me ("(at)vx/shape": "^0.0.153")

from visx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.