Comments (7)
Thanks for the report. Very happy to hear a successful story.
from hx.
I appreciate the time you put into writing this up! I'm glad you're feeling productive in it and that it's solving a pain point for you with other libraries.
A couple things that might help:
- Regarding Context: If you're using
reagent-context
, it might be easier to construct the Context value usingreact/createContext
(orhx.react/createContext
which is just a proxy for it) and then create areagent-context
type usingreagent-context.core/->Context
. Example:
(def my-app-context (react/createContext))
(def ctx (reagent-context.core/->Context my-app-context))
(hx.react/defnc [props]
(let [ctx-value (react/useContext my-app-context)]
[:div (prn ctx-value)]))
(reagent-context.core/defconsumer my-component ctx
[ctx-value prop1 prop2]
[:div (prn ctx-value)])
-
Regarding conversion of CLJS data to JS: This happens anytime you pass in props as an element (e.g.
[:div {:on-click #(js/alert "hi"}]
), and each time your components are rendered. hx only converts things to and from either shallowly - so for instance, passing in a hugely nested map as a prop won't have any performance penalty. Likewise, any JS data structures passed into your component will be left alone. The perf penalties in this case are not that bad. If you find yourself in a particularly hot-path and need to optimize, you can use JS interop in that one place without affecting the rest of your code. -
Regarding using JS data: You can use any CLJS data with all of the hooks. The only place that you have to use raw JS data is when passing in dependencies to things like
useEffect
;hx.hooks/useEffect
et. al. handles that conversion for you. You can certainly store CLJS data inside ofuseState
. Please do! -
Regarding naming: good feedback! I'll think about exposing the same functions with descriptive names, as well as adding docstrings to both of them.
Once again, thanks for taking the time to write this up and I hope that we can help aid in things like clearer documentation and easier interop with existing libraries.
from hx.
@tomconnors I would love some numbers about the code size. Did switching to hx reduce the final bundle size?
from hx.
This is an internal application so I haven't made any effort at all to optimize the build size. Tough to give any useful numbers because I added hx + react-dnd without removing reagent.
from hx.
Indeed, if you added react-dnd and hx at the same time it's impossible to compare. And you @Lokeh do you have some numbers?
from hx.
I don't know where to put it and this seems like the most appropriate place.
I tried to incorporate hx components in a Reagent app. Namely, I wanted to add react-beautiful-dnd
. I couldn't do it in Reagent alone since table dimension locking requires getSnapshotBeforeUpdate
which Reagent doesn't support yet. The example I tried to recreate: https://react-beautiful-dnd.netlify.com/?path=/story/tables--with-dimension-locking
All was well except for table dimensions not being locked. After a fun debug session, it turned out that I have to use react-beautiful-dnd
using only hx. I cannot use hx only for the component that requires getSnapshotBeforeUpdate
- I have to use it for the whole functionality.
I think the reason behind it is that React and Reagent have separate async rendering machinery. In the working example, getSnapshotBeforeUpdate
is fired before the styles of the parent component are updated. And in my version, it was consistently happening after, preventing table cells from locking their dimensions.
from hx.
@p-himik I think reagent has recently added support for new lifecycle methods like get-snapshot-before-update-test
reagent-project/reagent#443
from hx.
Related Issues (20)
- Destructuring defnc :keys [class] has weird behaviour HOT 1
- Improved react dev-tools support for hooks HOT 3
- CLJS data structures are compared by ref in <-effect deps HOT 11
- Semantics and API of <-state HOT 16
- class & className issue when wrapping defnc component with pure react component HOT 3
- Make it fast
- Reducers dont support Multimethods HOT 4
- Document hiccup parser API
- hx/f exceptions handlint HOT 4
- any HOT 1
- Export hooks under Clojure-style names HOT 2
- `defcomponent` API is very confusing HOT 1
- How-to contains misleading memo use HOT 7
- Push missing tags + maybe a 0.5.4 release HOT 2
- Docstring support for defnc (and defcomponent) HOT 1
- track dependencies to selectively rerender with useMemo HOT 3
- Passing down original js props in render props does not work with js->clj
- hx.hooks/useMemo deps as CLJS collection? HOT 1
- Typo in package 0.5.3 (maybe broken) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hx.