Enforce the use of keyGenerator in the ForEach parameter.
In scenarios where frame loss occurs during scrolling, modify the code according to this rule.
@Entry
@Component
struct ForeachTest {
private data: string[] = ['1', '2', '3'];
build() {
RelativeContainer() {
List() {
ForEach(this.data, (item: string, index: number) => {
ListItem() {
Text(item);
}
}, (item: string, index: number) => item)
}
.width('100%')
.height('100%')
}
.height('100%')
.width('100%')
}
} @Entry
@Component
struct ForeachTest {
private data: string[] = ['1', '2', '3'];
build() {
RelativeContainer() {
List() {
// Error: ForEach lacks the third parameter.
ForEach(this.data, (item: string, index: number) => {
ListItem() {
Text(item);
}
})
}
.width('100%')
.height('100%')
}
.height('100%')
.width('100%')
}
} plugin:@performance/recommended plugin:@performance/all
For details about how to configure Code Linter check rules, see Code Linter.