React 16.7 Hooks : `react.useState` is not a function










6















I am trying functional components with hooks of react 16.7,there is an error:



enter image description here



src/components/Footer/index.js



function Footer() 
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...



package.json



enter image description here



What should I do?










share|improve this question



















  • 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






  • 1





    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks

    – Yangshun Tay
    Nov 15 '18 at 0:09















6















I am trying functional components with hooks of react 16.7,there is an error:



enter image description here



src/components/Footer/index.js



function Footer() 
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...



package.json



enter image description here



What should I do?










share|improve this question



















  • 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






  • 1





    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks

    – Yangshun Tay
    Nov 15 '18 at 0:09













6












6








6








I am trying functional components with hooks of react 16.7,there is an error:



enter image description here



src/components/Footer/index.js



function Footer() 
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...



package.json



enter image description here



What should I do?










share|improve this question
















I am trying functional components with hooks of react 16.7,there is an error:



enter image description here



src/components/Footer/index.js



function Footer() 
const [selectedTab, setSelectedTab] = useState('redTab');
const [hidden, setHidden] = useState(false);
const [fullScreen, setFullScreen] = useState(false);
//...



package.json



enter image description here



What should I do?







reactjs react-hooks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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





    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks

    – Yangshun Tay
    Nov 15 '18 at 0:09












  • 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






  • 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












3 Answers
3






active

oldest

votes


















10














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>








share|improve this answer
































    2














    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.






    share|improve this answer
































      0














      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






      share|improve this answer






















        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
        );



        );













        draft saved

        draft discarded


















        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









        10














        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>








        share|improve this answer





























          10














          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>








          share|improve this answer



























            10












            10








            10







            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>








            share|improve this answer















            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>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 '18 at 0:01

























            answered Nov 13 '18 at 14:30









            TholleTholle

            42.9k54669




            42.9k54669























                2














                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.






                share|improve this answer





























                  2














                  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.






                  share|improve this answer



























                    2












                    2








                    2







                    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.






                    share|improve this answer















                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 13 '18 at 14:34

























                    answered Nov 13 '18 at 14:27









                    Hemadri DasariHemadri Dasari

                    10.2k32152




                    10.2k32152





















                        0














                        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






                        share|improve this answer



























                          0














                          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






                          share|improve this answer

























                            0












                            0








                            0







                            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






                            share|improve this answer













                            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







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 13 '18 at 14:13









                            Andrea GiammarchiAndrea Giammarchi

                            1,388711




                            1,388711



























                                draft saved

                                draft discarded
















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                                Edmonton

                                Crossroads (UK TV series)