Skip to content

Extend Node object #321

Open
Open
@diegocamy

Description

@diegocamy

Hi Jake, first of all, thank you for creating this library.

Is there a way to extend the Node object? I'm asking because I would like to have a path property.

What I did, that didn't work, was the following.

Created a file named react-checkbox-tree.d.ts in my types folder, and wrote the following

import { Node } from "react-checkbox-tree"

declare module "react-checkbox-tree" {
  interface Node {
    path: string
  }
}

I'm able to create a node using this interface but when I use the onClick function on my CheckboxTree component to console.log() the path, it shows undefined

<CheckboxTree
   nodes={nodes}
   noCascade
   expanded={expandedNodes}
   checked={checkedNodes}
   onExpand={(expanded) => setExpandedNodes(expanded)}
   onCheck={(checked) => setCheckedNodes(checked)}
   onClick={(node) => console.log(node.path)}
   showNodeIcon={false}
    />

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions