简体   繁体   中英

How to solve no-underscore-dangle error without making the error off in config

In my app, I had to add the following part e._targetInst.child.memoizedProps[0] but is giving esLint error no-underscore-dangle and I would like to solve it without disabling the error config.

The code where this is applied

const handleSelectSite = ({ onChange: onChangeSelectSite }) => {
            return e => {
              setOnFieldChangeConfirm(() => () =>
                onChangeSelectSite('siteId', e.target.value),
              );
              console.log(e._targetInst.child.memoizedProps[0]);
              setConfirmMsg(
                `${formatMessage(messages.confirmChangeMessage, {
                  previous: candidateSite,
                  newValue: e._targetInst.child.memoizedProps[0],
                })}`,
              );
              setConfirmDialog(true);
            };
          };


     
     

    

You can either ignore the linter error using // eslint-disable-next-line no-underscore-dangle or by destructuring and renaming:

const handleSelectSite = ({ onChange: onChangeSelectSite }) => {
  return e => {
    setOnFieldChangeConfirm(() => () =>
      onChangeSelectSite('siteId', e.target.value),
    );

    const { _targetInst: targetInst } = e;

    setConfirmMsg(
      `${formatMessage(messages.confirmChangeMessage, {
        previous: candidateSite,
        newValue: targetInst.child.memoizedProps[0],
      })}`,
    );
    setConfirmDialog(true);
  };
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM