dependency is something that is imported in the src/ or client/ module like you mentioned. The code that you run depends on it and hence is required in the production bundle.
If it were something like
Babel it could be a devDependency because:
- It is not imported in source code.
- It is a transpiler and works on code in compile time
But that is not the case with React. Functions like
setState or lifecycle hooks are being executed in run time, meaning the library has to be present during run time.
React could very well be listed as a peer dependency is some of the popuar libraries. This is because we assume that all projects that are going to use this library are going to have
React installed. Like consider the case of
react-bootstrap. It can only be run in react projects, so we include react as peer dependency reducing the overhead of installing it.
If you need a framework that would disappear in compile time, take a look at Svelte.
I had the same question and found this article that explains it well.
To summarize, it shouldn't matter where you put the react dependencies since Webpack will bundle them into a self-contained file and the code will run fine in either case. However, separating development and production dependencies allows for a better communication to other developers for the purpose of these dependencies.
dependencies are required to
devDependencies only to
React is a dependency because it is included in the final build.
In case of a React App, all your JSX is converted to a syntax similar to
React.createElement and hence you would require your App to have React during run time as well. Similary methods like
lifecyle functions are all executed during run-time.
As a matter of fact react is a library that has exposed some methods and APIs to access and manipulate DOM.
Consider this similar to
express where you add it in the production build because they are being used during run time.
When creating a react app, things like
webpack etc which are only used to create a bundle would be dev-dependencies as once the packaged bundle is generated it need not be generated during run time of application
- why react should usually be a prod dependency and not dev-dependency
- Why React Hook useState uses const and not let
- You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react
- why should I not use CDN for react & babel?
- Why is my React checkbox onChange handler firing on render and then not when the box is clicked?
- In React why does calling a function from another function in our code not work and display?
- React Native Reload and Dev Tools Do Not Work
- Prod build of React App allows React Dev Tools and show components in source tab inside Browser
- What is the benefit of having $sce or Strict Contextual Escaping in angularjs and why react does not need to do it?
- Why does my React app append the external URL to http://localhost:/<port> and not to ONLY the URL itself?
- Why do React lifecycle methods return `mixed` and not `void`?
- When should a react component be declared as a function, and not a class?
- Why is my ReactiveUserControl or React application not working with Selenium auto test and WinAppDriver (C# test solution)
- React Dev Tools not loading components and Events not firing
- Using React and Redux Hooks, why is my action not firing?
- Why objects are not valid as react children? What are valid children in react and why?
- How to Create a dropdown Button with see more option and on click toggle should not happen in react js?
- Getting TypeError: Cannot read property 'localeCompare' of undefined for my sortBy function in my React component and I'm not sure why
- Why is React state the init state and not the state I just set?
- Why I get 30 fps in chrome dev tool performance panel, but JS and React both say it's 60?
- Why got "This expression is not callable..." errors from typescript and react js?
- Why does React functionality not working on Chrome and Opera?
- Components not having the expected props, while React and Redux Dev Tools are having the expected States and Props
- Separate config for DEV and PROD of wepack5 not working
- Why does the state object in react not update properly? Expanded and collapsed version of object differ
- Why doesnt the condition evaluate to false when not specifically checking for undefined value using react and typescript?
- Why do the console.logs and UI in my React app not show the same state variable?
- React App - Why m count down is showing a dot whent the hours are equals to zero? And my minute is not 00 when pass of 59
- React - How can I let visitors use react dev tools but can not edit states and props
- Why does my React app menu open when I am only changing the state and am not using any CSS?
More Query from same tag
- State outside of my useCallback is different to the one that is inside
- React JS - setState and unwanted re-render
- Redirect from one page to another in react
- retrieving nested JSON objects when mapping from an api call
- In React, how can a parent change prop or state values on another component programatically?
- Can't set up React/Babel/Webpack
- React toggle button based on API return
- React +(Router) without webpack or browserify
- React Js, adding new object to an array
- How to highlight React tsx with PrismJS
- How to access route params from a component other then the Router component
- Reactjs - proptypes check with oneOfType
- React, undefined this
- Redux in NextJS
- Which is the best practise for using axios in React Project
- Custom "Previous" & "Next" text in react-table
- ReactJS - How can I implement pagination for react with keep state when route change?
- How to implement video with transparent background in react-native
- Password validation in reactjs
- native.createnavigator factory is not a function
- Redux-Thunk "Actions must be plain objects. Use custom middleware for async actions."
- Getting dynamic width of div after rendering
- How to redirect to a different page after authenticated with React
- React table horizontal scroll bar displayed only at end of vertical scroll bar
- React state value not updating
- useEffect() triggers components re-render in one function but not in the other one. Both function DO change state. What am I missing?
- Error occurs when react Modal is surrounded by Portal
- How to animate a sliding cart with react spring with a toggle button
- How does Express and React Routes work on initial GET request from browser?
- How do I mock a component that has a 'ref' with jest?