Skip to main content

useNiceDag(React)

In terms of React applications, you can simply use this customized react hook which is given by nice-dag-react module. Essentially, it's a wrapper of the API of nice-dag-core.

useNiceDag(args: UseNiceDagArgs): UseNiceDagType

Arguments(UseNiceDagArgs)

For the usage of react hook, the object extends NiceDagConfig. Besides its parent declarations, the below list show properties and API of it which need users to give.

Properties

NameOptionalDescriptionTypeDefault Value
editableYesIf it is true, the DAG diagram can be editable after initializationbooleanfalse
initNodesNoThe init nodes listNode[]
scrollPositionYesThe init position of scroll barPoint

For more properties, you can click here.

renderNode

(props: NiceDagNodeProps) => React.Component<any, any>;

The method is MANDATORY. The key of input is the node object. You can have different renders according to the content which the node contains.

renderEdge

(props: NiceDagEdgeProps) => React.Component<any, any>;

The method is OPTIONAL. If you give the method, it will be invoked once the DAG diagram initialization finishes.

onMount

() => void;

The method is OPTIONAL. If you give the method, it will be invoked once the DAG diagram initialization finishes.

Return (UseNiceDagType)

NameDescriptionType
niceDagElA react ref object links to a DOM (host of DAG diagram)react.MutableRefObject<any>
minimapElA react ref object links to a DOM (host of minimap diagram)react.MutableRefObject<any>
nicedagThe api set which can control the DAG diagramNiceDag
renderA function which performs rendering for the DAG diagram() => JSX.Element[]
resetA function which can reset the DAG diagram() => void;

Notes: The render method call MUST be called within a DAG diagram container.

Props Types

NiceDagNodeProps

NameDescriptionType
nodeThe node objectIViewNode
niceDagNice Dag objectNiceDAG

NiceDagEdgeProps

NameDescriptionType
edgeThe edge objectIEdge
niceDagNice Dag objectNiceDAG