Comments (4)
Mark
from react.
Mark
from react.
React does track the type of hook called (along with their order):
react/packages/react-reconciler/src/ReactFiberHooks.js
Lines 316 to 327 in d29f7d9
This check should (and does) catch the error when user breaks the rules of react. This is what I see in the console:
Warning: React has detected a change in the order of Hooks called by App. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks
Previous render Next render
------------------------------------------------------
1. useState useState
2. useRef useRef
3. useRef useRef
4. useEffect useRef
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Arguably there could be a case made for throwing and not just warning on hook type mismatch. I don't know the context here on why we chose to warn, @acdlite do you remember?
EDIT: Found the original PR (#14585), but not a lot of context there either. I'm going to close as this is working mostly ok -- we do warn with the correct error.
from react.
Thanks for your reply. I look through the console and do see this warning message.
There are lots of console messages in my project. When this error occurs, the last few messages in console and the Webpack error overlay are Cannot read properties of undefined
, leading me to wonder if it's a React bug... 😂
If this should remain "warning", maybe I'll find another way to let devs notice it.
from react.
Related Issues (20)
- Bug: Modify value of textarea value in react s page by javascript and select dropdown item by javascript HOT 2
- eslint-plugin-react-hooks & "Flat Config" (ESLint 9) HOT 10
- Bug: eslint-plugin-react-hooks still links to legacy.reactjs.org HOT 2
- Bug: eslint-plugin-react-hooks `exhaustive-deps` rule shouldn't warn when using an object's property HOT 3
- [DevTools Bug]: Consistent memory leak when refreshing on React + non-React websites. HOT 16
- Bug: Adding StrictMode component leads to cases that can't happen in concurrent mode. HOT 3
- Bug: <link> onLoad event happened but not triggered (18.2.0 & 18.3.0-canary-2e470a788-20240214) HOT 1
- Introducing `UseConstantState()` - A Novel Approach to Permanent State Management 🚀 HOT 6
- Bug: `textarea` inputs in Safari stop accepting input if certain lines are deleted HOT 5
- React Project Doesn't display on browser HOT 2
- Bug: Undo/Redo not behaving as expected for controlled input when state is updated from an async callback HOT 3
- Bug: React can leak the whole subtree when using contentEditable (reproduction sscce included) HOT 2
- Request: Define to exports cjs/* files in package.json
- Feature request: Define prop preprocessor
- Bug: errors caught by error boundaries appear in console twice HOT 1
- Bug: `flushSync` does not work HOT 2
- Bug: Next.js Build Errors Fix HOT 1
- Bug: Use useId function to generate dom id,it can't use document.querySelector function. HOT 6
- Bug: Despite having implemented optimizations such as shouldComponentUpdate or PureComponent HOT 7
- Bug: unable to compile standalone binary in Deno with server rendering, while using Typescript.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.