react-flow-chart icon indicating copy to clipboard operation
react-flow-chart copied to clipboard

Immutable chart state

Open djhahe opened this issue 5 years ago • 2 comments

Fixes #31

djhahe avatar Aug 27 '19 11:08 djhahe

It would be great to get this merged, as it would mean that the library could be used with hooks inside functional components!

function useChart(initialState: IChart): [IChart, typeof actions] {
  const [chart, setChart] = useState(initialState);
  const stateActions = useMemo(
    () =>
      Object.entries(actions).reduce(
        (prev, [key, val]) => ({
          ...prev,
          [key]: (...args: any) => setChart(val(...args))
        }),
        {}
      ) as typeof actions,
    [actions]
  );
  return [chart, stateActions];
}

fenech avatar Oct 22 '19 16:10 fenech

Is this pr being merged any time soon?

Have found some bugs on the validateLink function that are caused by this. The link.to property gets wiped when the function is called.

marcoalfonso avatar Feb 20 '20 03:02 marcoalfonso