useExhaustiveDependencies - Configurable Stable Hooks in biome.json #1034
Replies: 1 comment
-
Overall I like the proposal! It seems to add a lot of great value to the rule! And if the parent rule decided to add this feature, I think it's the right course of action to follow.
We can help you with that.
I believe we should be able to support a configuration that is more similar to the one proposed in the Facebook repository, it requires a bit more of code but it's doable :) "useExhaustiveDependencies": {
"level": "error",
"options": {
"hooks": [],
"stableHooks": {
"useRecoilState": true, // whole payload is stable
"useResetRecoilState": [true, false] // first index is stable, second index in not stable
}
}
} If you want to work more on this, feel free to create an issue (task) |
Beta Was this translation helpful? Give feedback.
-
Hello Biome Team,
I'm proposing an enhancement for the Biome linter, inspired by ESLint's handling of similar issues (Issue #16873). The key idea is to enable the specification of stable custom hooks in biome.json, akin to how React's useState is treated in dependency arrays.
Current Limitation:
Biome's use_exhaustive_dependencies rule doesn't currently distinguish between different types of setter functions from hooks. For example, in React, we don't need to include the setter function from useState in dependency arrays:
However, with similar hooks from other libraries, like useRecoilState from Recoil, the setter must be included:
Desired Feature:
I propose a feature to configure Biome in a way that allows us to treat setters from custom hooks (like useRecoilState) the same way as useState, not requiring them in the dependency array. This would ensure consistency and a smoother development experience.
Implementation Note:
In my attempt at implementing this feature (Commit f0433f18), I introduced an approach to mark specific return values of hooks as stable. However, there are some limitations and unconventional aspects to be aware of:
100
. This workaround was necessary because I encountered difficulties in handling null in biome.json as None in Rust due to my limited experience with the language.const [foo1, foo2, foo3, foo4] = useXxxx();
, even iffoo2
andfoo4
are stable, only one can be marked as such.While these limitations reflect my initial approach and understanding of Rust, I'm open to suggestions for more robust and flexible solutions from those with more experience in the language and ecosystem.
I believe this feature would be a valuable addition to Biome, and I look forward to any input or suggestions, especially regarding the implementation approach.
Beta Was this translation helpful? Give feedback.
All reactions