Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not use in react 18 #9

Open
Awen-hub opened this issue Aug 19, 2022 · 3 comments
Open

Can not use in react 18 #9

Awen-hub opened this issue Aug 19, 2022 · 3 comments

Comments

@Awen-hub
Copy link

By creating the project with react 18, I encounted the error Cannot read properties of undefined (reading 'sourceEvent') when selecting a range.
example

@bumbeishvili
Copy link
Owner

It looks like error is caused by using wrong d3 version. (v6, v7 will not work)

Here is a same example working when I am including d3 v5

https://stackblitz.com/edit/data-driven-range-slider-react-integration-rnn8gt?file=package.json,index.html

@Awen-hub
Copy link
Author

It's really strange because the error exists when I included "d3": "5.15.1" in package.json as you do.
Here is the example

@Awen-hub
Copy link
Author

It works when I change the code.

function brushed(d) {
      if (d.sourceEvent.type === "brush") return;
      if (attrs.freezeMin) {
        if (d.selection[0] < attrs.startSelection) {
          d.selection[1] = Math.min(d.selection[0], d.selection[1]);
        }
        if (d.selection[0] >= attrs.startSelection) {
          d.selection[1] = Math.max(d.selection[0], d.selection[1]);
        }

        d.selection[0] = 0;
        d3.select(this).call(d.target.move, d.selection);
      }

      var d0 = d.selection.map(scaleX.invert);
      const s = d.selection;

      handle.attr("display", null).attr("transform", function (d, i) {
        return (
          "translate(" + (s[i] - 2) + "," + (calc.chartHeight / 2 - 25) + ")"
        );
      });
      output({
        range: d0,
      });
    }

It seems to have no related with react v18. But I don't know why it works on older react version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants