Skip to content

Commit

Permalink
PR feedback: Remove useRef/on mount onChange catch for now
Browse files Browse the repository at this point in the history
- We don't currently need the extra catch for any live components, and it's confusing
  • Loading branch information
cee-chen committed Apr 14, 2021
1 parent 5d97f84 commit 3931eb3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,5 @@ describe('MultiInputRows', () => {

expect(onChange).toHaveBeenCalledWith(['updated']);
});

it('does not submit on initial render/mount (due to useRef)', () => {
setMockValues({ ...values, values: ['initial value'] });
shallow(<MultiInputRows {...props} onChange={onChange} />);

expect(onChange).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect, useRef } from 'react';
import React, { useEffect } from 'react';

import { useValues, useActions } from 'kea';

Expand Down Expand Up @@ -47,12 +47,10 @@ export const MultiInputRows: React.FC<Props> = ({
const { values, hasEmptyValues, hasOnlyOneValue } = useValues(logic);
const { addValue, editValue, deleteValue } = useActions(logic);

const hasChanged = useRef(false);
useEffect(() => {
if (onChange && hasChanged.current) {
if (onChange) {
onChange(filterEmptyValues(values));
}
hasChanged.current = true;
}, [values]);

return (
Expand Down

0 comments on commit 3931eb3

Please sign in to comment.