Is there a “reagent way” to insert meta
tags in the <head>
of the dom the application is running in? I’ve figured out a way to do it with javascript interop and directly manipulating the dom, but wondering if there is a more reagent way to do it that could be fed with data from re-frame or r/atoms
Re-frame effects are meant for this kind of things.
Basically it’s just a bit more controlled way to do what you already do with interop and you get to pick data from app-db or any other coeffects
The re-frame is one part, but the other part was wondering if there is a more reagent way to append / update / insert into the <head>
The only think I found was to render into head but that seemed to replace the whole head not add to it.
I tried to use https://github.com/nfl/react-helmet with Reagent, but I couldn’t get it to work. It wasn’t clear how to get it to fit into the Reagent way of starting the app.
Head is usually “outside” the react render tree. Imo using dom manipulation side-effect would be idiomatic :thinking_face:
I mean, to me it would be more weird if reagent did side-effects outside its render tree
Yeah, I need to be able to dynamically create meta tags to support https://support.shareaholic.com/hc/en-us/articles/115005177166-Adding-Meta-Tags-using-JavaScripthttps://ogp.me/. Some of the data in the tag isn’t known until the page is being loaded.
But thanks for the reminder that I should probably do the interop in an effect. That will solve one problem I’m having
I read this 2017 post about reagent speed https://yogthos.net/posts/2017-03-26-ReagentReactView.html and I realized that I don't quite understand how cursors work
in the example that @yogthos writes, a given cursor is created within for
loops:
(for [idx (range (count (:players @game)))]
^{:key idx}
[player-component (reagent/cursor game [:players idx])])
doesn't that re-create the cursor every time the enclosing function is called?