附带规则警告使用效果

时间:2019-08-06 20:19:33

标签: react-hooks use-effect

写这种效果的正确方法是什么

此代码仅适用于eslint警告,我认为可以忽略

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]
   );
   .
   .
   .
   .

0 个答案:

没有答案