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.

Hooks API Discussion

See original GitHub issue

Somebody was going to ask eventually! The new hooks API could possibly help here. I think most of the API can pretty much stay the same, with the HOC mapping directly into a hook.

I do wonder if we can replace connectDragSource and connectDropTarget with just passing in the value of useRef. It could definitely make stuff cleaner if that’s possible!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:43 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
darthtrevinocommented, Mar 20, 2019

So, to ease up on my earlier comment, the API in #1280 is shaping up to be better than I first thought. Feel free to comment here or there

1reaction
darthtrevinocommented, Mar 20, 2019

So I spent a bunch of time last night reworking the hooks API to use connector functions. As far as API design goes, I really fucking hate it.

My next thought is that we can return a callback-ref instead of a ref-object. This should give us flexibility to use as a ref directly or to pass a ref into it

Using Directly:

let [props, dragSource] = useDrag({spec}) // dragSource result is a function
return <div ref={dragSource} {...props}>hey</div>

Chaining

let [dragProps, dragSource] = useDrag({spec})
let [dropProps, dropTarget] = useDrag({spec})

return <div ref={node => dragSource(dropTarget(node))}>hey</div>

With Ref Object

let ref = useRef(null)
let [dragProps, dragSource] = useDrag({spec})
let [dropProps, dropTarget] = useDrag({spec})
dragSource(dropTarget(ref))

return <div ref={ref}>hey</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks API Reference
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 >
Discussion: Potential hooks API design · Issue #1179
Let's use this thread to discuss actual design considerations for an actual hooks API. Prior references: #1063: Provide React Hooks #1177: ...
Read more >
React New hook | In Discussion | use() - YouTube
Their is a discussion ongoing on react panel about proposing a new hook which will be use to fetch data from API and...
Read more >
Clean API Call With React Hooks
Hi Stefan,. I don't think so. We often focus first on things that have direct benefits to most users (e.g. performance, security...). But...
Read more >
APIs and Hooks
APIs and Hooks. ... How to re-use custom code page functionality in api? Started by vinay_jadhav. 0 Replies 399 Views. HOOK / Changes...
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