naisutech/react-tree

Having trouble figuring out controls api

lhenkel opened this issue · 1 comments

I'm trying to write something that expands out a nested node given an id. I've been trying to make some of the examples work, but drawing a blank on any except onSelect.

I'm new enough to React that the example

        {(controls) => {
            return <button onClick={() => controls.toggleOpenCloseAllNodes()}>Open/close all nodes</button>
        }}

Didn't make sense or at least seem to do anything when I pasted it in.

I saw this:

https://naisutech.github.io/react-tree/?path=/docs/react-tree--with-controls

But the code it showed

onOpenClose={function noRefCheck(){}}

Doesn't seem to do anything when I copied it.

Here's a sandbox of my attempt at following the example:

https://codesandbox.io/s/naisu-techreact-tree-demo-forked-5d5sc?file=/src/index.js

Can someone point me in the right direction? Thanks.

Hi @lhenkel -- it seems you're now using an outdated and very old version of the library in your sandbox. The latest published version (with the controls API is version > 2).

I updated your demo with the new version and added an example use of the controls. Hope it helps!
https://codesandbox.io/s/naisu-tech-react-tree-demo-v2-0-11-0in55?file=/src/index.js