react-flow-chart
react-flow-chart copied to clipboard
Immutable chart state
Fixes #31
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];
}
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.