Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a ReactJS Component with Clojurescipt/Reagent

Is it possible to wrap ReactJS components for use with Reagent in Clojurescript? I have read that it is. Can someone provide me with a basic example?

Thanks

like image 816
ducky Avatar asked Nov 24 '14 17:11

ducky


People also ask

What is reagent ClojureScript?

Reagent is a ClojureScript wrapper around React. It gives you a way to easily create React components. Reagent has three main features that make it easy to use: using functions to create React components, using Hiccup to generate HTML, and storing state in Reagent Atoms.

Where do I put the React component in logic?

As you said, React is just the V in the MVC. So, where do you put your business logic? For small, view-specific business logic, it's ok to put that on the component, as you did. If the business logic is in the component, it's going to be on an event-handler, in the render or any other component method.

How do you call a function from another file in native React?

To import a function from another file in React: Import the function in file B as import {sum} from './another-file' . Use the imported function in file B .


1 Answers

Here is my solution for it (I am going to use a React-Bootstrap Panel Component):

1) Include react-bootstrap.min.js in your html.

2) Here is a sample usage of the Panel component:

(def PanelComp (. js/ReactBootstrap -Panel))
(defn page
  []
  [:div
   [:div [PanelComp {:header "Panel heading without title"} "Panel content"]]])
like image 153
ducky Avatar answered Nov 09 '22 09:11

ducky