MrBlenny / react-flow-chart

🌊 A flexible, stateless, declarative flow chart library for react.
https://mrblenny.github.io/react-flow-chart/index.html
MIT License
1.48k stars 306 forks source link

How to get data from newly created flow chart? #116

Closed Nilanth closed 4 years ago

Nilanth commented 4 years ago

Need support, I need to create a flow chart in FrontEnd and need to send the data to backend, how to get the flow chart data, so i can reproduce the flow chart by API response?

@MrBlenny could you please help with this.

It could be better if you add this to the docs!

Thanks.

altran-fabian commented 4 years ago

i get to manage it like this:

add a new ref in your container:

this.state = chartData
const flowchartRef = React.createRef();

later access it with

const thatData = flowchartRef.current.state
this.setState(thatData)

pass the ref to your chart:

<FlowChart ref={flowchartRef} chartData={this.state}/>

than in your flowchart component initialize it with React.forwardRef:

const FlowChart = React.forwardRef((props,ref) => {
    let chartData = props.chartData
    return (<FlowChartWithState
      ref={ref}
      initialValue={chartData}
              />)})

hope that helps ;)