Provide React Hooks
See original GitHub issueToday’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:
- Created 5 years ago
- Reactions:233
- Comments:85 (29 by maintainers)
Top 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 >Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
BTW, to be clear about versioning stuff, here’s what I’d like to do:
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.
BTW, this wasn’t coordinated at all, but React is telling us to do this 😄
https://reactjs.org/docs/hooks-faq.html#what-do-hooks-mean-for-popular-apis-like-redux-connect-and-react-router