vasturiano / react-force-graph

React component for 2D, 3D, VR and AR force directed graphs

Home Page:https://vasturiano.github.io/react-force-graph/example/large-graph/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use useRef with Typescript?

kyrregjerstad opened this issue · comments

I'm trying to use useRef with typescript, but I cannot seem to get the correct type for the ref. What would be the correct way to set this up?

import { ForceGraph3D } from 'react-force-graph';

const Graph = () => {
    const ref = useRef<WhatGoesHere?>();
    
    return (
        <ForceGraph3D
        ref={ref}
        ...
        />
    )
}

Hope this helps:

import { ForceGraphMethods } from 'react-force-graph-3d'
...
const ref = useRef<ForceGraphMethods>()