React hooks & context
See original GitHub issueI’d love to be able to use react hooks in react-blessed.
It’s an RFC, now, but looks like it will probably solidify into mainline react, soon. In order to test, I installed react@16.7.0-alpha.2
.
As it is, I get this error:
Invariant Violation: Hooks can only be called inside the body of a function component.
with this code:
import React, { useState, useEffect } from 'react'
import fetch from 'node-fetch'
function App () {
const [posts, setPosts] = useState([])
useEffect(async () => {
const items = await fetch(
'https://jsonplaceholder.typicode.com/posts'
).then(r => r.json())
setPosts(items.map(i => i.title))
})
return (
<list items={posts} />
)
}
To verify that the hooks work, etc, here is a similar thing in a sandbox, in react-dom.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Hooks API Reference - React
This page describes the APIs for the built-in Hooks in React. ... If you're familiar with the context API before Hooks, useContext(MyContext) is...
Read more >React useContext Hook - W3Schools
React Context is a way to manage state globally. It can be used together with the useState Hook to share state between deeply...
Read more >A Guide to React Context and useContext() Hook
The context in React is a concept that lets you supply child components with global data, no matter how deep they are in...
Read more >How and When to Use Context in React with Hooks
Context allows you to pass data across any number of React components, regardless of nesting. Redux or Context? In a very small application,...
Read more >How to useContext in React - Robin Wieruch
React's useContext Hook takes the Context as parameter to retrieve the value from it. Using the React Hook instead of the Consumer component ......
Read more >Top Related Medium Post
No results found
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
Hello @konsumer. I agree it would be nice to have hooks support. Unfortunately I am not even sure the current codebase is able to work with react@16 since a lot of changes were made to the reconciler logic. I have not much time to work on this but will of course consider any PR.
Ah, I got it. needed
mouse
for buttons to work. Ok, ready for review.