question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[discussion] ReSub Hook API

See original GitHub issue

I was wondering whether there are any plans to officialy support React Hooks. I only found a discussion regarding lifecycle changes (#78) but could not find a mention of the now introduced Hooks.

It is definitely possible to use them, I have made an example repository as a proof of concept here: https://github.com/Hizoul/ReSubHooksTest

Ideally I imagine the API to work the same as _buildState so like this:

  const state = useResub(() => {
    value: FormStore.getValue("My key")
  })

(Where FormStore is an autosubscribe score that has an @key decorator on its first argument) Unfortunately due to my lack of understanding of decorators and how automatic subscriptions work I was only able to come up with a solution that requires the key to be specified explicitly.

  const state = useResub(FormStore, "My key", {name: "getValue", arguments: ["My key"]})

The hook implementation with annotations for parts that need to be improved can be found here: https://github.com/Hizoul/ReSubHooksTest/blob/master/src/resubHook.js

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Hizoulcommented, Feb 7, 2019

Thank you for the clarification! In the unlikely event of me figuring out an implementation that supports the automatic subscriptions I will let you know. I wouldn’t dare opening a pull request for the ugly Proof-of-Concept API portrayed in the second code block.

0reactions
deregtdcommented, Jun 12, 2020

I ended up adding a hook-like API to use for now. We may also someday add a full useResub() state-builder, if there’s demand for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks API Reference - React
This page describes the APIs for the built-in Hooks in React. If you're new to Hooks, you might want to check out the...
Read more >
Hooks - React Redux
Hooks. React's new "hooks" APIs give function components the ability to use local component state, execute side effects, and more.
Read more >
React Reference Guide: Hooks API - LogRocket Blog
This reference guide will discuss all the Hooks natively available in React, but first, let's start with the basic React Hooks: useState ...
Read more >
Not sure how to test call to REST hook, documentation unclear
I'm trying to set up a REST Hook api request. I can trigger the hook, but nothing happens. Maybe something goes wrong in...
Read more >
REST Hook - Capsule API
REST Hook. REST Hooks allow you to subscribe to certain events in Capsule. When those events are triggered, Capsule will send a JSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found