A library for accessing React 16 context in Reagent

After talking in another thread about how to properly theme a reagent application (especially one which is using SSR on Node.js), I decided to finally dig into how to use the new, official React context API with reagent.

A small library was born out of that:

It mostly works to paper over a lot of the boilerplate one needs when doing interop with React components that use children-as-a-function. It also is an effort to provide a more Clojure-y API around creating & using the context API.

A big reason I’m looking for some community support is to help fix some of the struggles with children-as-a-function & reagen, outlined in the gotchas section above.

Still though, I hope this saves someone else a weekend of work!

3 Likes

Neat! I can imagine this coming in handy when I need to interact with third-party code that uses Contexts.

In the other thread you mentioned that with-redefs didn’t work for your theming use case, but did you try binding? Its effects should be thread-local.

I made an update there :slight_smile: basically, due to some cleverness I’m doing to load data while server rendering, it would be very gross to thread the theme binding through each async context. I think that React context is something that could be better leveraged for this kind of synchronous state, and I think it opens up a replacement for other things where threading state through an application either requires props drilling, or global variables.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.