M
M
Maksipes2020-06-19 16:11:09
JavaScript
Maksipes, 2020-06-19 16:11:09

Is memoization applied correctly?

For example, there is a function that pulls out something needed by the key from the passed string (inside the regurak)

function getValueByType(type, someString ) {
  const value = ....
  return value;
}


there are a lot of extra renderers, without changing someString props and I want to memoize this function.

I do like this:

const getListId = memoizeOne((someString) => getValueByType('list', someString));
const getItemId = memoizeOne((someString) => getValueByType('item', someString));


and then in render:
const listId = getListId(someString);
const item = getItemId(someString);

Do I understand correctly that getListId and getItemId will return the calculated value once until someString changes?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question