JSFiddle - React, Tailwind, and code Playground

by amindunited

JavaScript

const trackingRef1 = '12345';
const trackingRef2 = '123456';
const trackingRef3 = '1234567';
const trackingRef4 = '12345678';

const articleValue = { consignmentId: '12345' };

const store = {};

const getArticleValue = () => ( articleValue );

const getStoredValue = (store) => ({ articleState: articleValue });

/*
const storeHasArticle = (trackingRef) => {
  let match = false;

  if (getStoredValue(store).articleState && getArticleValue(store)) {
    const storedId = getArticleValue(store).consignmentId;
    match = (storedId === trackingRef) ? true : false;
  }
  return match;
};
*/

const storeHasArticle = (trackingRef) => {
  if (!getStoredValue(store).articleState || !getArticleValue(store)) {
    return false;
  }
  return trackingRef === getArticleValue(store).consignmentId;
};

storeHasArticle(trackingRef1);
storeHasArticle(trackingRef2);
storeHasArticle(trackingRef3);
storeHasArticle(trackingRef4);