1

How is the rigth way to write this effect

this code works only has a eslint warning, I considered that is good to ignore

const Select = ({ value }) => {

  const [selectedOption, setSelectOption] = useState(() => value);

  useEffect(
   () => {
     if (value !== selectedOption) {
       setSelectOption(value);
     }
   },
   // I need to ignore eslint rule here
   // I need an effect that update my value when change from parent, 
   // but only when is different that the selected value to avoid 
   // rerenders and when is updated by the same component in onChange event
   // that allow to use my component isoleted with any parent value
   // eslint-disable-next-line
     [value]
   );
   .
   .
   .
   .
4

0 に答える 0