Search code examples
reactjscommandversioncreate-react-app

How create a react app with a specific version using the npx command?


I want to create a React app using the command

npx create-react-app my-app

But I want to make sure I can choose the React version. I want a version that can't use hooks, so I want to force a React version before 16.8 (in which hooks were released).

How or where do I find the version to use?
I have followed a tutorial that gave me a command like

npx create-react-app reactjs-app --scripts-version 1.1.5

How can I create an app with for example React version 16.7?

My goal is to get the latest version before which hooks were released.


Solution

  • According the documentation the syntax for npx is:

    npx [options] <command>[@version] [command-arg]...
    

    If you want react version 16.7 you have to find out which version of create-react-app installs react 16.7 because the version numbers are not the same. If I'm correct version 3.4.1 of create-react-app installs the latest version of react before they introduce hooks.

    can simply run:

    npx create-react-app@3.4.1 my-app