foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.09k stars 129 forks source link

poc - remove lodash head #634

Closed cmolenda closed 7 months ago

cmolenda commented 7 months ago

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.

lodash's head implementation with length check:

function head(array) {
    return array != null && array.length ? array[0] : undefined;
}

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

cmolenda commented 7 months ago

Was just a demo in case we ever need to remove lodash. At this time, not considered a priority.