react-force-graph icon indicating copy to clipboard operation
react-force-graph copied to clipboard

Loading state

Open otaviobonder-deel opened this issue 3 years ago • 5 comments

First of all, great lib. Second awesome lib I'm using from you, thank you!

I'm using the warmupTicks={50} because I'm loading a big dataset. Everything is working, with minor performance issues moving the graph. While the graph is loading (after data is ready) it shows a blank screen. Is it possible to add a loader while the graph is warming up?

Thanks!

otaviobonder-deel avatar Jan 19 '21 20:01 otaviobonder-deel

@otaviobps thanks for reaching out. Glad the lib is working out well for you.

For this loading purpose, I would suggest using the onEngineTick event handler to detect when the loading is done, and just overlay a loading indicator before that. The warmup section of the graph does not trigger onEngineTick events.

vasturiano avatar Jan 22 '21 00:01 vasturiano

Hi @vasturiano - huge fan as well of the library. Do you have an example of onEngineTick and the parameters? I wasn't able to find one and was having a similar issue.

timtutt avatar Mar 12 '21 12:03 timtutt

@timtutt that prop is simply an event function that gets called at every tick of the engine. It doesn't receive any arguments. So you'd use it something like this:

onEngineTick={() => /* your logic here */}

vasturiano avatar Mar 12 '21 13:03 vasturiano

Thanks much fo the response here. I think the piece I was missing here is that I should be looking for the first occurrence of onEngineTick to change the state?

timtutt avatar Mar 15 '21 12:03 timtutt

@timtutt if you're trying to determine if it's the first time that method is invoked, you can just keep state in your app that tracks it. Probably as simple as:

const [hasLoaded, setHasLoaded] = useState(false);
(...)
onEngineTick={() => setHasLoaded(true)}

vasturiano avatar Mar 15 '21 12:03 vasturiano