How to use the dot-object.override function in dot-object

To help you get started, we’ve selected a few dot-object examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DJanoskova / React-validator-demo / src / utils / validatorWithTooltip.js View on Github external
const handleChange = useCallback(({ target }) => {
    const { value, checked, type } = target;
    const newValue = type === 'checkbox' ? checked : value;

    // using dot helps us change nested values
    let data;
    const isNested = name.includes('.');
    if (isNested) {
      dot.override = true;
      data = dot.str(name, newValue, { ...formData });
    }
    else data = { ...formData, [name]: newValue };

    setValue(newValue);
    setFormData(data);
  }, [setValue, formData, setFormData, name]);
github DJanoskova / React-validator-demo / src / utils / validator.js View on Github external
const oldValue = dot.pick(name, formData) || [];
    const { checked } = target;
    let newValue;

    const index = oldValue.indexOf(value);
    if (checked && index < 0) {
      newValue = [...oldValue, value]
    } else if (!checked && index > -1) {
      newValue = oldValue.filter(v => v !== value);
    }

    // using dot helps us change nested values
    let data;
    const isNested = name.includes('.');
    if (isNested) {
      dot.override = true;
      data = dot.str(name, newValue, { ...formData });
    } else {
      data = { ...formData, [name]: newValue };
    }

    setChecked(checked);
    setFormData(data);
  }, [value, formData, setFormData, name]);

dot-object

dot-object makes it possible to transform and read (JSON) objects using dot notation.

MIT
Latest version published 8 months ago

Package Health Score

63 / 100
Full package analysis