- Language: Typescript React
- Rule #: S6440
- False Positive Reason: The hook is being called at the top of the component/hook, not nested in any loop or condition.
- Version: Data Center Edition v2025.1.2 (108896)
There is a for loop in the code, but the hook itself isn’t being called in the for loop.
Example of code flagged as a bug
// this flags typescript s6440
const useFileData = () => {
const { filePrefix } = useFileContext()
const files: Array<string> = []
for (let i = 2; i <= 5; i++) {
files.push(filePrefix + `${i}.json`)
}
// ...rest of logic
}
Example of equivalent code that isn’t considered a bug
const useFileData = () => {
const { filePrefix } = useFileContext()
const files = Array.from({ length: 4 }, (_, i) => filePrefix + `${i + 2}.json`)
// ...rest of logic
}
I already have eslint which is capable of warning for the rules of hooks, and it doesn’t flag this code.