Code Monkey home page Code Monkey logo

Comments (3)

AnneTee avatar AnneTee commented on May 24, 2024 1

Any reason why you're doing the manual search + setting data? The component will do this for you.

This component is just one search filter of many that I'm using to query a Solr instance.

Most likely you're setting state in your onChange which causes the dropdown to re-render. If the dropdown data hasn't changed, you can prevent this re-render by following the approach here: prevent-re-render-on-parent-render-hoc

The component is definitely re-rendering, but the weird part is that when a top-level item is selected, the dropdown remains open after the re-render, but when a child component is selected it immediately closes.

That said, I took your advice and prevented the component from re-rendering when the parent component renders and things are working as expected now. Thanks for your quick response and this useful component!

from react-dropdown-tree-select.

mrchief avatar mrchief commented on May 24, 2024

I'm sending the data upstream so the search can be performed. When the app re-renders, my search filter receives the selected items as props, and then I'm editing the data I'm providing to the to set the proper items as checked = true.

Any reason why you're doing the manual search + setting data? The component will do this for you.

There is a prop called showDropdown which will render the component with dropdown open. But that will not solve your issue completely since the search input will get cleared if you re-render the component.

I'll also note that when I remove my custom onChange function, the dropdown stays open

Most likely you're setting state in your onChange which causes the dropdown to re-render. If the dropdown data hasn't changed, you can prevent this re-render by following the approach here: prevent-re-render-on-parent-render-hoc

from react-dropdown-tree-select.

mrchief avatar mrchief commented on May 24, 2024

This component is just one search filter of many that I'm using to query a Solr instance.

Very interesting use case.

but the weird part is that when a top-level item is selected, the dropdown remains open after the re-render

It's weird. The only reason I can think of is that somehow the whole component is getting re-instantiated (thus destroying state and closing the dropdown).

from react-dropdown-tree-select.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.