shadaj/slinky

Documentation on using JS React Hooks

nadenf opened this issue · 2 comments

It is not that clear how to use external JS React Hooks such as: url-double-click.

It would be good to add documentation here. In particular around how to pass Refs to JS React Hooks.

evbo commented

Not sure if I'm oversimplifying this, but I've found external hooks to be pretty similar to writing facades as with other external js libraries. For instance, the popular QuillJS rich text editor is a simple one that involves refs too:

class UseQuill(val quill: js.UndefOr[Quill], val quillRef: ReactRef[Any]) extends js.Object

@js.native
@JSImport("react-quilljs", "useQuill")
object useQuill extends js.Function0[UseQuill] {
  override def apply(): UseQuill = js.native
}
evbo commented

I think it can be as simple as above based on how hooks are implemented as just simple functions. For instance, here are some custom hooks that are quite simple:

https://github.com/payalabs/use-slinky-hooks/blob/master/src/main/scala/com/payalabs/slinky/hooks/GenericHooks.scala