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.

Using react hooks with ink: Invariant Violation

See original GitHub issue

Hey,

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:closed
  • Created 5 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

8reactions
vadimdemedescommented, Feb 15, 2019

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!

4reactions
zkatcommented, Feb 16, 2019

This should be fixed now ✌️ See #124

Read more comments on GitHub >

github_iconTop 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 >

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