Giter Site home page Giter Site logo

Comments (5)

holmsand avatar holmsand commented on May 8, 2024

Yes, that it definitely a bug (and yes, that is kind of a dark corner both of Reagent and React...).

My (admittedly rather ugly) code tries to work around that React's controlled components don't like asynchronous rendering. Inputs with an onChange handler only allow changes when that handler runs (that code in React seems to have moved here: https://github.com/facebook/react/blob/master/src/browser/dom/components/ReactDOMInput.js - see in particular the shouldComponentUpdate method).

I'll have a think about what's going wrong as well.

And if you want look for a fix: the easiest way to run the tests, and play with the code in general, is to run "make runtest" in the top-level directory. That builds the entire demo-site, and runs tests both in browser and node. Probably doesn't work on windows, where something like lein with-profile test,dev cljsbuild auto client may be required.

from reagent.

holmsand avatar holmsand commented on May 8, 2024

I think I've found an acceptable solution, in e539069

For "controlled components", Reagent now sets the value of inputs directly, rather than going through React, and schedules a forceUpdate whenever on-change is run, so that the value of the input is reset to its original value unless on-change leads to an update of the :value property.

That way, the value of the input field and the underlying atom should always be kept in sync.

from reagent.

mainej avatar mainej commented on May 8, 2024

Thanks @holmsand! The fix is a little more complicated than I expected, but it makes sense. Looking forward to testing it in your next release.

from reagent.

holmsand avatar holmsand commented on May 8, 2024

Yes, it was a little more complicated than I expected too at first :)

Btw (and sorry if this is blindingly obvious to you), if you want to test it right now, you can just do lein install in the Reagent directory, and then change your dependency on Reagent in your project.clj to [reagent "0.4.2-SNAPSHOT"].

from reagent.

mainej avatar mainej commented on May 8, 2024

Works great! Thanks for the tips - still new to clojure and lein.

from reagent.

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.