remix-hook-form icon indicating copy to clipboard operation
remix-hook-form copied to clipboard

null / undefined handling

Open TheYoxy opened this issue 1 year ago • 0 comments

As is, when you create a form data with a value that has been defined with a value, even values that represents nothing (null and undefined), it gets serialized in string.

Wouldn't it be better to ignore theses values or return the raw underlined type ?

One idea of test implementation in the case that the choice is to handle base type:

  describe('should handle undefined', () => {
    it('with stringify all', () => {
      const data = {
        undefined: undefined,
      };
      const formData = createFormData(data, true);
      expect(formData.get('undefined')).toEqual(undefined);
    });
    it('with stringify all', () => {
      const data = {
        undefined: undefined,
      };
      const formData = createFormData(data, false);
      expect(formData.get('undefined')).toEqual(undefined);
    });
  });
  describe('should handle null', () => {
    it('with stringify all', () => {
      const data = {
        null: null,
      };
      const formData = createFormData(data, true);
      expect(formData.get('null')).toEqual(null);
    });
    it('with stringify all', () => {
      const data = {
        null: null,
      };
      const formData = createFormData(data, false);
      expect(formData.get('null')).toEqual(null);
    });
  });

TheYoxy avatar Jul 17 '24 16:07 TheYoxy