Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is lazy loading possible? #36

Closed
kulshekhar opened this issue Jan 22, 2018 · 3 comments
Closed

Is lazy loading possible? #36

kulshekhar opened this issue Jan 22, 2018 · 3 comments

Comments

@kulshekhar
Copy link

There are two somewhat related parts to this question:

  • Is it possible to lazily load child nodes when the parent (or some ancestor) is expanded?
  • Is it possible to use a remote service to fetch search results instead of using only the locally available data?

Nice work on this component btw. It seems very useful. 👍

@mrchief
Copy link
Collaborator

mrchief commented Jan 22, 2018

Its not something the component supports natively but its doable with an HOC (Higer Order Component).

It'd be something like:

class HOC extends Component {
  ...
  onNodeToggle = ({id, expanded}) => {  // assumes that initial data has an unique id property for each node
    if(!expanded) {  // you can do more like check if data is already fetched then skip this
      // fetch remote data
      this.setState({ data: merge(data, remoteChildNodeData) }) 
    }
  }

  render() {
    const { data } = this.state
    return (
      <DropdownTreeSelect data={data} onNodeToggle={onNodeToggle} />
    )
  }
}

I understand this may not be perfect but its a start. If you want the component to support this natively, then we need a bigger discussion.

@kulshekhar
Copy link
Author

@mrchief thanks. This seems like a viable option :)

@bimix
Copy link

bimix commented Apr 16, 2024

Its not something the component supports natively but its doable with an HOC (Higer Order Component).

It'd be something like:

class HOC extends Component {
  ...
  onNodeToggle = ({id, expanded}) => {  // assumes that initial data has an unique id property for each node
    if(!expanded) {  // you can do more like check if data is already fetched then skip this
      // fetch remote data
      this.setState({ data: merge(data, remoteChildNodeData) }) 
    }
  }

  render() {
    const { data } = this.state
    return (
      <DropdownTreeSelect data={data} onNodeToggle={onNodeToggle} />
    )
  }
}

I understand this may not be perfect but its a start. If you want the component to support this natively, then we need a bigger discussion.

once the state is updated the dropdown will be refreshed and all nodes will collapse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants