34
rated 0 times
[
40]
[
6]
/ answers: 1 / hits: 19693
/ 6 Years ago, tue, december 4, 2018, 12:00:00
TL;DR: I'm trying to use the new react-hooks
api, but I keep getting an Invariant Violation error when calling the setState
hook, but it keeps failing.
import React, { useState } from 'react';
// type State = {
// heading: string;
// }
const Text = () => {
const initialState = 'Heading'.toUpperCase();
const [heading, setHeading] = useState(initialState);
return (
<header>
<h1>
{setHeading('Brussels')};
{heading}
</h1>
</header>
);
};
export default Text;
More From » reactjs