Removing lodash head from Field causes a mobx warning. It's a known
function of mobx that it will consider 0 index of an empty array as out of
bounds (which is actually correct) but JS will return undefined. For
our case, we can avoid it entirely by checking if it's empty before
accessing it, which is part of how lodash's head is implemented.
It is not something that they plan to change in Mobx. Instead, there is
a flag to turn off the warning in production, should we choose to simply
ignore the warning and try to access anything in the empty array.
Removing lodash
head
from Field causes a mobx warning. It's a known function of mobx that it will consider 0 index of an empty array as out of bounds (which is actually correct) but JS will returnundefined
. For our case, we can avoid it entirely by checking if it's empty before accessing it, which is part of how lodash's head is implemented.lodash's head implementation with length check:
It is not something that they plan to change in Mobx. Instead, there is a flag to turn off the warning in production, should we choose to simply ignore the warning and try to access anything in the empty array.
@see https://github.com/mobxjs/mobx/issues/2913