Using react hooks with ink: Invariant Violation
See original GitHub issueHey,
I am trying to use the new react hooks with Ink components, but I get the error:
Invariant Violation: Hooks can only be called inside the body of a function component.
I am using the hooks inside a function component, so I guess it is related to Ink implementation?
Here is the code:
import React, {useState} from 'react'
import {h, render, Component} from "ink";
function useTest() {
const [value, update] = useState(Date.now());
return [value, update]
}
const Demo = () => {
const [value, update] = useTest();
setInterval(() => {
update(Date.now())
}, 1000)
return <div>Hello: {value}</div>
}
class Wrapper extends Component<any, any>{
render() {
return <Demo />
}
}
render((<Wrapper />));
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (11 by maintainers)
Top Results From Across the Web
Invalid Hook Call Warning - React
There are three common reasons you might be seeing it: You might have mismatching versions of React and React DOM. You might be...
Read more >invariant violation, invalid hook call, useApolloClient
What I want is to get use the useApollo hook to get the client then use the clearStore on the client. How can...
Read more >React Hooks Testing Library: Introduction
Simple and complete React hooks testing utilities that encourage good testing ... Invariant Violation: Hooks can only be called inside the body of...
Read more >Invariant Violation: Objects are not valid as a React child
Objects are not valid as a React child (found: object with keys {value}). If you meant to render a collection of children, use...
Read more >Tips to replace Recompose's HOCs with React Hooks for ...
I'm the solo developer of Inkdrop, a Markdown note-taking app. ... I've already adopted React Hooks in the desktop version earlier and I ......
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 Free
Top 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
Now that hooks are officially released, I will look into how to make Ink work with them 😃 Thanks everyone for helpful input!
And of course, if somebody’s already solved this problem, PRs are always welcome!
This should be fixed now ✌️ See #124