Comments (7)
function MyComponent() {
const [id] = React.useState(() => Math.random());
// Doesn’t require [id] since it will never change
useAutoEffect(() => {
console.log(id);
});
const [counter, setCounter] = React.useState(0);
// Again, `setCounter` is not used, `counter` will never change!
const values = useAutoMemo(new Array(counter));
const handleLog = React.useCallback(() => {}, []);
// `handleLog` will (*should*) never change, using as a dependency is reduntant
useAutoEffect(() => handleLog('Hallo!'));
}
from hooks.macro.
Please see #11 and #12 for further discussion on those additional optimizations.
from hooks.macro.
This is a very nice suggestion! We could also exclude:
- the state value if the setter is never used
- memoized values/callbacks that use an empty dependencies array
from hooks.macro.
Thanks for the response!
I'm not sure I quite understand your suggestions. It would be awesome if you could show an example of each of them.
from hooks.macro.
Found the relative code in the ESLint exhaustive-deps rules: https://github.com/facebook/react/blob/fe2cb525542443aaf1447c4069354c12659fd186/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js#L296
Should be straight forward to add them to this macro.
from hooks.macro.
@Glinkis you can see this implemented in v1.1.0. Should bring those small perf improvements :)
from hooks.macro.
Thanks!
from hooks.macro.
Related Issues (16)
- Extract indirect dependencies
- Create a debug/trace facility
- Create an escape hatch HOT 2
- Rules for property accesses HOT 9
- Create a generic form HOT 2
- Bail out on constants HOT 1
- Error/warn on known non-invariants
- TypeScript support HOT 2
- State values with unused setters are known to be static (if const)
- Memoized values with empty inputs array are known to be static
- Known static return value from react-redux hook HOT 1
- useAutoUpdateEffect HOT 2
- Not adding dynamic components to dependencies HOT 3
- Feature request: debugChangedDependencies HOT 2
- Support React 17? HOT 5
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 hooks.macro.