React 16.7 Hooks : `react.useState` is not a function
I am trying functional components with hooks of react 16.7,there is an error:
src/components/Footer/index.js
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...
package.json
What should I do?
reactjs react-hooks
add a comment |
I am trying functional components with hooks of react 16.7,there is an error:
src/components/Footer/index.js
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...
package.json
What should I do?
reactjs react-hooks
1
Are you sure you have installed it and not just bumped the version inpackage.json
? Try to removenode_modules
and install again:rm -rf ./node_modules && npm install
. Make sure you upgradereact-dom
to the same version as well.
– Tholle
Nov 13 '18 at 14:10
1
Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 '18 at 0:09
add a comment |
I am trying functional components with hooks of react 16.7,there is an error:
src/components/Footer/index.js
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...
package.json
What should I do?
reactjs react-hooks
I am trying functional components with hooks of react 16.7,there is an error:
src/components/Footer/index.js
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...
package.json
What should I do?
reactjs react-hooks
reactjs react-hooks
edited Nov 13 '18 at 14:23
skyboyer
4,17811333
4,17811333
asked Nov 13 '18 at 14:08
zwl1619zwl1619
1,09242045
1,09242045
1
Are you sure you have installed it and not just bumped the version inpackage.json
? Try to removenode_modules
and install again:rm -rf ./node_modules && npm install
. Make sure you upgradereact-dom
to the same version as well.
– Tholle
Nov 13 '18 at 14:10
1
Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 '18 at 0:09
add a comment |
1
Are you sure you have installed it and not just bumped the version inpackage.json
? Try to removenode_modules
and install again:rm -rf ./node_modules && npm install
. Make sure you upgradereact-dom
to the same version as well.
– Tholle
Nov 13 '18 at 14:10
1
Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 '18 at 0:09
1
1
Are you sure you have installed it and not just bumped the version in
package.json
? Try to remove node_modules
and install again: rm -rf ./node_modules && npm install
. Make sure you upgrade react-dom
to the same version as well.– Tholle
Nov 13 '18 at 14:10
Are you sure you have installed it and not just bumped the version in
package.json
? Try to remove node_modules
and install again: rm -rf ./node_modules && npm install
. Make sure you upgrade react-dom
to the same version as well.– Tholle
Nov 13 '18 at 14:10
1
1
Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 '18 at 0:09
Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 '18 at 0:09
add a comment |
3 Answers
3
active
oldest
votes
Make sure that you upgrade react-dom
to 16.7.0-alpha.0
as well.
package.json
"dependencies":
"react": "16.7.0-alpha.0",
"react-dom" "16.7.0-alpha.0",
...
,
...
It might also be that you only bumped the version in package.json
without installing the new version. You can remove node_modules
and install again.
npm ci
Example
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
add a comment |
React and react-dom versions are different in your package.json
So to fix the issue you need to upgrade react-dom to the same version as react
Run below command. This will install react-dom version 16.7.0-alpha.0
npm i -s react-dom@16.7.0-alpha.0
After installing react-dom re bundle the project.
add a comment |
I have installed both react and react-dom alpha, as you can see in this package.json.
Using, in the same project, the following code, would work just fine:
import React, useRef, useState from 'react';
function Counter()
const [count, setCount] = useState(0);
const [icount, setICount] = useState(0);
const current: increment = useRef(1 + Math.floor(Math.random() * 5));
return (
<div>
Count count<br />
Increment increment<br />
<button onClick=() =>
setCount(count + 1);
setICount(icount + increment);
clicks=count>
Current icount
</button>
</div>
);
export default Counter;
That export can be tested/used via a basic app like:
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter';
ReactDOM.render(<Counter />, document.body);
I hope this example clarifies/solves your issues.
Best Regards
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282848%2freact-16-7-hooks-react-usestate-is-not-a-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Make sure that you upgrade react-dom
to 16.7.0-alpha.0
as well.
package.json
"dependencies":
"react": "16.7.0-alpha.0",
"react-dom" "16.7.0-alpha.0",
...
,
...
It might also be that you only bumped the version in package.json
without installing the new version. You can remove node_modules
and install again.
npm ci
Example
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
add a comment |
Make sure that you upgrade react-dom
to 16.7.0-alpha.0
as well.
package.json
"dependencies":
"react": "16.7.0-alpha.0",
"react-dom" "16.7.0-alpha.0",
...
,
...
It might also be that you only bumped the version in package.json
without installing the new version. You can remove node_modules
and install again.
npm ci
Example
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
add a comment |
Make sure that you upgrade react-dom
to 16.7.0-alpha.0
as well.
package.json
"dependencies":
"react": "16.7.0-alpha.0",
"react-dom" "16.7.0-alpha.0",
...
,
...
It might also be that you only bumped the version in package.json
without installing the new version. You can remove node_modules
and install again.
npm ci
Example
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
Make sure that you upgrade react-dom
to 16.7.0-alpha.0
as well.
package.json
"dependencies":
"react": "16.7.0-alpha.0",
"react-dom" "16.7.0-alpha.0",
...
,
...
It might also be that you only bumped the version in package.json
without installing the new version. You can remove node_modules
and install again.
npm ci
Example
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
const useState = React;
function Footer()
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
return (
<div>
<button onClick=() => setSelectedTab('blueTab')>selectedTab</button>
<button onClick=() => setHidden(isHidden => !isHidden)>
hidden ? 'hidden' : 'visible'
</button>
<button onClick=() => setFullScreen(isFullScreen => !isFullScreen)>
fullScreen ? 'fullscreen' : 'windowed'
</button>
</div>
);
ReactDOM.render(
<Footer />,
document.getElementById('root')
);
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script>
<div id="root"></div>
edited Nov 20 '18 at 0:01
answered Nov 13 '18 at 14:30
TholleTholle
42.9k54669
42.9k54669
add a comment |
add a comment |
React and react-dom versions are different in your package.json
So to fix the issue you need to upgrade react-dom to the same version as react
Run below command. This will install react-dom version 16.7.0-alpha.0
npm i -s react-dom@16.7.0-alpha.0
After installing react-dom re bundle the project.
add a comment |
React and react-dom versions are different in your package.json
So to fix the issue you need to upgrade react-dom to the same version as react
Run below command. This will install react-dom version 16.7.0-alpha.0
npm i -s react-dom@16.7.0-alpha.0
After installing react-dom re bundle the project.
add a comment |
React and react-dom versions are different in your package.json
So to fix the issue you need to upgrade react-dom to the same version as react
Run below command. This will install react-dom version 16.7.0-alpha.0
npm i -s react-dom@16.7.0-alpha.0
After installing react-dom re bundle the project.
React and react-dom versions are different in your package.json
So to fix the issue you need to upgrade react-dom to the same version as react
Run below command. This will install react-dom version 16.7.0-alpha.0
npm i -s react-dom@16.7.0-alpha.0
After installing react-dom re bundle the project.
edited Nov 13 '18 at 14:34
answered Nov 13 '18 at 14:27
Hemadri DasariHemadri Dasari
10.2k32152
10.2k32152
add a comment |
add a comment |
I have installed both react and react-dom alpha, as you can see in this package.json.
Using, in the same project, the following code, would work just fine:
import React, useRef, useState from 'react';
function Counter()
const [count, setCount] = useState(0);
const [icount, setICount] = useState(0);
const current: increment = useRef(1 + Math.floor(Math.random() * 5));
return (
<div>
Count count<br />
Increment increment<br />
<button onClick=() =>
setCount(count + 1);
setICount(icount + increment);
clicks=count>
Current icount
</button>
</div>
);
export default Counter;
That export can be tested/used via a basic app like:
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter';
ReactDOM.render(<Counter />, document.body);
I hope this example clarifies/solves your issues.
Best Regards
add a comment |
I have installed both react and react-dom alpha, as you can see in this package.json.
Using, in the same project, the following code, would work just fine:
import React, useRef, useState from 'react';
function Counter()
const [count, setCount] = useState(0);
const [icount, setICount] = useState(0);
const current: increment = useRef(1 + Math.floor(Math.random() * 5));
return (
<div>
Count count<br />
Increment increment<br />
<button onClick=() =>
setCount(count + 1);
setICount(icount + increment);
clicks=count>
Current icount
</button>
</div>
);
export default Counter;
That export can be tested/used via a basic app like:
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter';
ReactDOM.render(<Counter />, document.body);
I hope this example clarifies/solves your issues.
Best Regards
add a comment |
I have installed both react and react-dom alpha, as you can see in this package.json.
Using, in the same project, the following code, would work just fine:
import React, useRef, useState from 'react';
function Counter()
const [count, setCount] = useState(0);
const [icount, setICount] = useState(0);
const current: increment = useRef(1 + Math.floor(Math.random() * 5));
return (
<div>
Count count<br />
Increment increment<br />
<button onClick=() =>
setCount(count + 1);
setICount(icount + increment);
clicks=count>
Current icount
</button>
</div>
);
export default Counter;
That export can be tested/used via a basic app like:
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter';
ReactDOM.render(<Counter />, document.body);
I hope this example clarifies/solves your issues.
Best Regards
I have installed both react and react-dom alpha, as you can see in this package.json.
Using, in the same project, the following code, would work just fine:
import React, useRef, useState from 'react';
function Counter()
const [count, setCount] = useState(0);
const [icount, setICount] = useState(0);
const current: increment = useRef(1 + Math.floor(Math.random() * 5));
return (
<div>
Count count<br />
Increment increment<br />
<button onClick=() =>
setCount(count + 1);
setICount(icount + increment);
clicks=count>
Current icount
</button>
</div>
);
export default Counter;
That export can be tested/used via a basic app like:
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter';
ReactDOM.render(<Counter />, document.body);
I hope this example clarifies/solves your issues.
Best Regards
answered Nov 13 '18 at 14:13
Andrea GiammarchiAndrea Giammarchi
1,388711
1,388711
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282848%2freact-16-7-hooks-react-usestate-is-not-a-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you sure you have installed it and not just bumped the version in
package.json
? Try to removenode_modules
and install again:rm -rf ./node_modules && npm install
. Make sure you upgradereact-dom
to the same version as well.– Tholle
Nov 13 '18 at 14:10
1
Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 '18 at 0:09