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











up vote
6
down vote

favorite












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 at 14:10






  • 1




    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
    – Yangshun Tay
    Nov 15 at 0:09















up vote
6
down vote

favorite












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 at 14:10






  • 1




    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
    – Yangshun Tay
    Nov 15 at 0:09













up vote
6
down vote

favorite









up vote
6
down vote

favorite











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 at 14:23









skyboyer

3,18611128




3,18611128










asked Nov 13 at 14:08









zwl1619

98231739




98231739








  • 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 at 14:10






  • 1




    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
    – Yangshun Tay
    Nov 15 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 at 14:10






  • 1




    Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
    – Yangshun Tay
    Nov 15 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 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 at 14:10




1




1




Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 at 0:09




Possible duplicate of TypeError dispatcher.useState is not a function when using React Hooks
– Yangshun Tay
Nov 15 at 0:09












3 Answers
3






active

oldest

votes

















up vote
8
down vote



accepted










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






























    up vote
    2
    down vote













    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






























      up vote
      0
      down vote













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








        up vote
        8
        down vote



        accepted










        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



























          up vote
          8
          down vote



          accepted










          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

























            up vote
            8
            down vote



            accepted







            up vote
            8
            down vote



            accepted






            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 at 0:01

























            answered Nov 13 at 14:30









            Tholle

            33.5k53558




            33.5k53558
























                up vote
                2
                down vote













                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



























                  up vote
                  2
                  down vote













                  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

























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    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 at 14:34

























                    answered Nov 13 at 14:27









                    Hemadri Dasari

                    7,02111039




                    7,02111039






















                        up vote
                        0
                        down vote













                        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

























                          up vote
                          0
                          down vote













                          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























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            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 at 14:13









                            Andrea Giammarchi

                            1,343711




                            1,343711






























                                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.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • 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

                                Costa Masnaga

                                Fotorealismo

                                Sidney Franklin