I am in the process of adding Formik to my React-Native project and have run into a problem where whenever I try to change form values, I get the following error:
TypeError: Invalid value used as weak map key.
It seems that the data that Formik is dispatching is correct, but it is throwing this error when executing the setIn function when updating form values which uses the lodash toPath method. This tries to turn the string ('salary', in my case) into a path by doing the following:
var stringToPath = memoizeCapped(function(string) {
var result = [];
if (string.charCodeAt(0) === 46 /* . */) {
result.push('');
}
string.replace(rePropName, function(match, number, quote, subString) {
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
});
return result;
});
The problem is that while this method actually works and computes the correct output ['salary'], it then gives me the above TypeError due to the memoizeCapped wrapper. If I remove the memoizedCapped, then everything works fine.
memoizeCapped.js:
function memoizeCapped(func) {
var result = memoize(func, function(key) {
if (cache.size === MAX_MEMOIZE_SIZE) {
cache.clear();
}
return key;
});
var cache = result.cache;
return result;
}
The resolver (second argument to memoize) in the above function will just return the first argument 'salary' when it is called inside memoize, which is causing the error as weak map keys must be objects.
The Formik library works on a fresh React-Native project, so there must be something we have changed that is causing this error but I am at a loss as to what it could be that is affecting the implementation of lodash.memoize. Also, if this is the case then _stringToPath.js should always give this error, so clearly I am missing something important.
I would very much appreciate some help if anyone has seen this sort of issue before?