reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
tatut 2020-03-25T09:19:28.001Z

Is there a convenient way to use react context? I got something working by React.createContextand adapting the Provider and Consumer classes in the returned object

tatut 2020-03-25T09:19:56.001700Z

but the context value will be turned into js and it's not very convenient to use

tatut 2020-03-25T09:21:34.002600Z

if there was a way to wrap something around the reagent rendering, you could use dynamic variables for context...

2020-03-25T10:45:00.004Z

I am speaking for myself: not always feasible but I found re-frame, event/subscription model easy to use to simulate the context

juhoteperi 2020-03-25T11:58:25.006500Z

Dynamic variables are problematic for Reagent rendering, as render happens asynchronously at some point. Reagent implementation could wrap the render bodies in a call that sets the dynamic properties always, but another (bigger maybe) problem is that if a node is rendered, its parent aren't necessarily rendered, so dynamic vars from those wouldn't get set. But this might be related to ideas I have around controlling rendering more.

juhoteperi 2020-03-25T12:00:55.008200Z

Docs have a very simple example for using React.createContext and Provider/Consumer, but it's probably same as what @tatut is already doing. Not sure what the problem is, but to workaround default properties conversion, using r/create-element might help

juhoteperi 2020-03-25T12:01:35.008900Z

(r/create-element Consumer {:clj :map ...} ...) should keep the properties object as clj map

👍 1
juhoteperi 2020-03-25T12:03:13.010100Z

If that helps, I can update the docs to mention this.

juhoteperi 2020-03-25T12:05:11.011100Z

Maybe all the docs should be rewritten to first recommend using r/create-element for interop, and then say, if you want to automatically convert clj properties to JS object, use adapt-react-class or :>

tatut 2020-03-25T15:10:06.011800Z

that worked well, with a minor wrapper to autocreate context by keyword name, the API is pretty simple