Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/hxPublic

A simple, easy to use library for React development in ClojureScript.

License

NotificationsYou must be signed in to change notification settings

nosco/hx

Repository files navigation

Clojars Project

A simple, easy to use library for React development in ClojureScript.

Update - Transfer of ownership

Theoriginal author has kindly agreed to transfer ownership of this project to Nosco. We're using hx in production and don't expect any breaking changes, but we are fixing small issues and minor quality of life improvements as we find them.

Development from theoriginal author has moved tohelix. Helix is the latest version of hx, with some breaking changes (no hiccup parser, slightly different hooks API, and a focus on compile-time semantics).

Example

(nsmy-app.core  (:require [hx.react:as hx:refer [defnc]]            [hx.hooks:as hooks]            ["react-dom":as react-dom]));; `defnc` creates a function that takes a props object and returns React;; elements. You may use it just like any normal React component.(defncMyComponent [{:keys [initial-name]}];; use React Hooks for state management  (let [[name update-name] (hooks/useState initial-name)]    [:<>     [:div"Hello"       [:span {:style {:font-weight"bold"}} name]"!"]     [:div [:input {:on-change #(update-name (-> % .-target .-value))}]]]))(react-dom/render;; hx/f transforms Hiccup into a React element.;; We only have to use it when we want to use hiccup outside of `defnc` / `defcomponent`  (hx/f [MyComponent {:initial-name"React in CLJS"}])  (. js/document getElementById"app"))

Dependencies

You'll want to make sure you have the latest version ofreact, and whateverrenderer you are targeting (e.g.react-dom).

npm i react react-dom

If you want to use the React Hooks API (hx.hooks), you'll need to ensureyou are using React 16.8 or later.

What problems doeshx solve?

hx is meant to make it simple, easy and fun to useReact.jswithin ClojureScript. It is your bridge to the wide world of React.js inidiomatic CLJS.

The library is split into (currently) three sections, which you can feel free tomix as your project sees fit:

  1. A hiccup interpreter. Takes in[:div {:style {:color "red"}} [:span "foo"]] andspits outReact.createElement calls.

  2. Helpers for creating components.defnc anddefcomponent help us writeplain React.js components in idiomatic ClojureScript.

  3. Helpers for using React Hooks.

What problems doeshxnot solve?

No opinionated state management, no custom rendering queue. Use it to buildyour awesome opinionated async reactive immutable app framework.hx is justa Clojure-y interface to creating plain, unadulterated React components.

Documentation

Examples

Interop:

Projects that use it

License

Copyright © 2018 Will Acton

Distributed under the MIT license.


[8]ページ先頭

©2009-2025 Movatter.jp