Reagent
GuideAPIChangelogGitHub
  • Documentation index
  • Getting Started
  • Reagent 2
    • What's new in 2.0
    • Upgrading to 2.0
  • Learn
    • Using Hiccup to Describe HTML
    • Creating Reagent Components
    • Square brackets vs parentheses
    • When do components update?
    • Managing State
    • Batching and Timing
    • Controlled Inputs
    • Best Practices (draft)
  • Reference
    • Interop with React
    • React Features
    • Reagent Compiler
    • Web Components (Custom Elements)
    • React Renderers
    • Server Side Rendering
    • React 19 and Reagent
    • Security
  • FAQ
    • Component not re-rendering
    • Using refs
    • Entities like nbsp
    • HTML entities
    • Missing attributes
    • dangerouslySetInnerHTML
    • Forcing re-creation
    • Broken after updating deps
  • Older versions
    • Upgrading to 1.2
    • Upgrading to 1.1
    • Upgrading to 1.0
    • Upgrading to 0.8
  • More
    • Example: Material-UI
    • Example: Smooth UI
    • Development guide
  • API
    • API reference
    • reagent.core
    • reagent.dom.client
    • reagent.dom
    • reagent.dom.server
    • reagent.ratom
    • reagent.hooks

Not reviewed yet: this page may be outdated or inconsistent with the other guides. The API reference is generated from the current source.

How do I force component re-creation?

React key with a stateful component

React key can be used to provide identity for components even outside of lists. If the key changes, the component is recreated triggering all the implemented stateful methods (did-unmount, did-mount etc.):

(defn comp []
  [:div
   ^{:key dynamic-id}
   [stateful-component]])

Edit this page on GitHub

GitHub · cljdoc · #reagent on Clojurians Slack · Archive
On this page
  • React key with a stateful component