React TS - Can you assign default values to a map()?

Asked
Active3 hr before
Viewed126 times

2 Answers

react
90%

you're not returning a value from the callback.,you're not using the array it returns; and/or, Since map builds a new array, using it when you aren't using the returned array is an anti-pattern; use forEach or for...of instead.

// Arrow function
map((element) => {
   ...
})
map((element, index) => {
   ...
})
map((element, index, array) => {
   ...
})

// Callback function
map(callbackFn)
map(callbackFn, thisArg)

// Inline callback function
map(function callbackFn(element) {
   ...
})
map(function callbackFn(element, index) {
   ...
})
map(function callbackFn(element, index, array) {
   ...
})
map(function callbackFn(element, index, array) {
   ...
}, thisArg)
load more v
88%

Pretag
 Pretag team - issue, fix, solve, resolve

Other "react-undefined" queries related to "React TS - Can you assign default values to a map()?"