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.

Provide React Hooks

See original GitHub issue

Today’s the big day for React Hooks!

Assuming the API gets released, we should provide some hooks. Something like useRedux would be cool!

import * as actions from './actions'

function Counter() {
  const [count, {increment, decrement}] = useRedux(state => state.count, actions);
  
  return (
    <>
      Count: {count}
      <button onClick={() => increment()}>+</button>
      <button onClick={() => decrement()}>-</button>
    </>
  );
}

Note: Yes, I’m aware of useReducer. That is for a Redux-style reducer, but for a local component’s state only. What we’re building would be for the store’s global state, using useContext under the hood.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:233
  • Comments:85 (29 by maintainers)

github_iconTop GitHub Comments

45reactions
timdorrcommented, Nov 7, 2018

BTW, to be clear about versioning stuff, here’s what I’d like to do:

  • 6.x.0 - Add Hooks as a new API and maintain a React >= 16.4 compat. Add invariant checks around Hooks for React <16.7. No other changes to the library.
  • 7.0.0 - Start using Hooks internally for our existing connect() API. Require React >= 16.7.

So, a minor and then a major. We go all-in, but gradually. Obviously, this depends a lot on how Hooks turn out, both from an API/pattern perspective and a performance/ergonomics perspective.

43reactions
timdorrcommented, Oct 25, 2018

BTW, this wasn’t coordinated at all, but React is telling us to do this 😄

In the future, new versions of these libraries might also export custom Hooks such as useRedux()

https://reactjs.org/docs/hooks-faq.html#what-do-hooks-mean-for-popular-apis-like-redux-connect-and-react-router

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing Hooks - React
With Hooks, you can extract stateful logic from a component so it can be tested independently and reused. Hooks allow you to reuse...
Read more >
Hooks at a Glance - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. Hooks are...
Read more >
Hooks API Reference - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. This page...
Read more >
Rules of Hooks - React
Don't call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function, before any...
Read more >
Using the State Hook - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. The introduction...
Read more >

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