Giter VIP home page Giter VIP logo

Comments (2)

holmsand avatar holmsand commented on May 21, 2024

That's because you create a new atom every time my-awesome-widget runs in the second example, which means that it will always have the value "hello".

To make it convenient to use local atoms like that, Reagent allows you to return a new function from the component, that will be called in the future when the component has changed. Like this:

(defn timer-component []
  (let [seconds-elapsed (atom 0)]
    (fn []
      (js/setTimeout #(swap! seconds-elapsed inc) 1000)
      [:div
       "Seconds Elapsed: " @seconds-elapsed])))

The returned function will be called with exactly the same arguments as the top-level function.

You can see that in action here: http://holmsand.github.io/reagent/index.html

from reagent.

Frozenlock avatar Frozenlock commented on May 21, 2024

Ah! Of course!
And I already read this tutorial. Shame that I forgot about this after only a few hours.

My apologies, seems like some of my Clojure reflexes are hard to shed. ;-)

Thanks for Reagent by the way, it's amazing!

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.