thoth-org / Thoth.Elmish.Toast

https://thoth-org.gitbook.io/thoth-elmish-toast/
MIT License
6 stars 4 forks source link

Use with Feliz.useElmish #44

Open PawelStadnicki opened 2 years ago

PawelStadnicki commented 2 years ago

In standard Elmish, Toast requires "registration" in the program entity:

Program.mkProgram init update view
|> Toast.Program.withToast Toast.render
|> Program.run

I wonder if it is possible to use this library along with Feliz hooks . It still will be command on Update:

state, 
      Toast.message "I am toast of type Info"
      |> Toast.title "Info"
      |> Toast.info

but I have no idea where the registration part should happen. I'm not asking how to do it, expecting implementation changes required, just checking if this is feasible and with what effort.

MangelMaxime commented 2 years ago

Hello,

I don't think it can work because Feliz don't expect an Elmish program with a view because it doesn't offer a clean way to attach the view.

I guess you could pass a program with a Program.withReact instruction but it would feel dirty to mount a react application inside of a react app.

I think React portal are a way to fix it but I don't know if this will require fixes from Feliz too or just Thoth.Elmish.Toast.

In React world there is https://www.npmjs.com/package/react-toastify which seems to offer something equivalent but using Hooks API instead.

There is also https://react-hot-toast.com/ which is smaller if bundle size is important to you.