


( js/setTimeout #( swap! seconds-elapsed inc) 1000) You just write a regular clojurescript function which takes data as parameters and produces a Hiccup vector. In the simplest case, a component collapses down to only be a render function. The three creation methods differ only in terms of what they supply over and above a renderer. In all three cases, a render function is provided - that's the backbone. via a map of functions, one of which is the render the rest of the functions are React lifecycle methods which allow for some more advanced interventions.via a function which returns the render function - the returned function is the render function.via a simple render function - data in as parameters, and it returns HTML.Ordered by increasing complexity, they are: There are three ways to create a component. Data is supplied via the function parameters, and Hiccup is the return value. In fact, as you'll soon see, components will often collapse down to be nothing more than a render function.Ī render function turns data into Hiccup. A render function is the backbone, mandatory part of a component. Core of a Component: the Render FunctionĪt the core of any component is a render function. And although it is convienent to refer to these render functions as "components," the more precise way to describe them is that they are normal ClojureScript functions that are used by the reagent library to create React components. The function you provide will serve as the component's render function. But apart from actual React components, you will find documentation (including the very next section of this guide) often refering to reagent render functions as "components." The dual use of this term can be confusing if you forget that most of the time, you will be dealing with these plain ClojureScript functions, which are often pure functions returning plain data.Įventually, you will provide these render functions (described below as Form-1 and Form-2 components) to reagent via re/render or re/as-element, which will wrap them with state-tracking funcionality and turn them into React components. You can create these in reagent directly using reagent/create-class. First, there is the underlying JavaScript React.Component class that React is built upon. The term component has multiple meanings when using reagent. What is a "Component"įirst a note about terminology. Reagent lets you create React components too, but most kinds of webpages can be created with Reagent using standard ClojureScript functions. In React, all components are first declared as objects or classes, and then instantiated using React.createElement or using JSX. (ns exampleĪ discussion of the details of rendering are found after we introduce components. The primary entrypoint to the reagent library is re/render. Hiccup describes HTML elements and user-defined components as a nested ClojureScript vector: Reagent uses a datastructure known as Hiccup to describe HTML. Getting props and children of current component.Example: "Decorator" Higher-Order Components.Creating React Components from Reagent "Components".Creating Reagent "Components" from React Components.Creating React Elements from Hiccup forms.Batching and Timing: How Reagent Renders Changes to Application State.Managing state: atoms, cursors, Reactions, and tracking.The difference between parenthesis and square brackets.Form-3: A Class With Life Cycle Methods.How Reagent Knows the Difference Between Form-1 and Form-2.Form-2: A Function Returning A Function.Core of a Component: the Render Function.Special interpretation of class attribute.Special interpretation of style attribute.
