Fork me on GitHub
#reagent
<
2018-08-07
>
felbit13:08:19

Hi Channel, how would you handle flash messages with reagent? I think I might doin’ things wrong. My error messages (like: user already exists) are not rendered at all. Is there a resource to ses how it is done right, somewhere?

rnagpal14:08:30

@mp747 by flash message you mean you want to show the massage for few secs and then make it disappear ?

felbit14:08:45

@rnagpal I mean the session flash messages that have a livespan of exactly one request.

rnagpal14:08:29

livespan of exactly one request will have to be managed by you

rnagpal14:08:37

so you can use a ratom

rnagpal14:08:14

something like

(def component-error  (reagent/ratom nil)) 

(defn component[] 
[:div 
 (when @component-error [error-message @component-error] )
[:div ......]])

rnagpal14:08:47

and then when you make a request you can reset the component-error to nil

rnagpal14:08:06

The solution depends on how reusable you want to code to be

rnagpal14:08:33

The code above for showing error message is tied to a component

felbit14:08:15

Thanks for your message 🙂 I do get that. My question is more: the error happened somewhere in the backend (e.g. a database error) and I want to show that to the user.

justinlee16:08:21

@mp747 there’s no built in mechanism like in rails or meteor. you’ll have to craft your own convention and return the error string

lilactown16:08:23

yeah. reagent is a purely front-end wrapper for React. it sounds like macchiato might be interesting to you? you'll want to hook into whatever your backend has support for flash messages

felbit17:08:02

@lee.justin.m coming from Rails that is something, that I do miss, though. What would be the idiomatic way to do it in Clojure/Script? Are there any (up to date) resources on this?

lilactown17:08:25

@mp747 what are you using instead of Rails on the backend?

felbit17:08:35

@lilactown I started with Luminus and Compojure-api

lilactown17:08:00

luminus has an example in their docs of passing data in a flash session

lilactown17:08:15

you can use some back-end templating to show that to the user. it doesn't have anything to do with reagent