3

I've trying to get ref and want to check whether it has value.

It has value at first time, but when I resize the chart it disappears.

I think this issue would related with react not the chart library.

Any ideas?

/j https://codesandbox.io/s/billboardjs-resize-onresize-bug-28fvz

const Page1 = props => {
  const [isResize, setIsResize] = useState(false);
  const chartRef = createRef();

  const options = {
    onresize(ctx) {
      console.log(chartRef.current);
      setIsResize(true);
    },
    onresized(ctx) {
      setIsResize(false);
    },
    data: {
      columns: [
        ["data1", 30, 200, 100, 170, 150, 250],
        ["data2", 130, 100, 140, 35, 110, 50]
      ],
      types: {
        data1: "line",
        data2: "area-spline"
      },
      colors: {
        data1: "red",
        data2: "green"
      }
    }
  };
  return (
    <div>
      <Chart
        className="timelineChart"
        options={options}
        isResize={isResize}
        ref={chartRef}
      />
    </div>
  );
};
JillAndMe
  • 3,989
  • 4
  • 30
  • 57

1 Answers1

4

I guess this is because the options object is keeping the first ref, and createRef() always return a new ref.

Use useRef() instead of createRef()

Let me know if it helps.

I tried it on JillAndMe link and it works: https://codesandbox.io/s/billboardjs-resize-onresize-bug-28fvz

François Richard
  • 6,817
  • 10
  • 43
  • 78